Class: Store::Digest::Entry::Flags
- Inherits:
-
Struct
- Object
- Struct
- Store::Digest::Entry::Flags
- Defined in:
- lib/store/digest/entry.rb
Overview
These is a struct for the bank of flags, with a couple of extra methods for parsing
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#charset_checked ⇒ Object
Returns the value of attribute charset_checked.
-
#charset_valid ⇒ Object
Returns the value of attribute charset_valid.
-
#encoding_checked ⇒ Object
Returns the value of attribute encoding_checked.
-
#encoding_valid ⇒ Object
Returns the value of attribute encoding_valid.
-
#syntax_checked ⇒ Object
Returns the value of attribute syntax_checked.
-
#syntax_valid ⇒ Object
Returns the value of attribute syntax_valid.
-
#type_checked ⇒ Object
Returns the value of attribute type_checked.
-
#type_valid ⇒ Object
Returns the value of attribute type_valid.
Class Method Summary collapse
-
.from(arg) ⇒ Store::Digest::Entry::Flags
Initialize a struct of flags from arbitrary input.
-
.to_i(array) ⇒ Integer
Turn an arbitrary Array back into an Integer.
Instance Method Summary collapse
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def cache @cache end |
#charset_checked ⇒ Object
Returns the value of attribute charset_checked
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def charset_checked @charset_checked end |
#charset_valid ⇒ Object
Returns the value of attribute charset_valid
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def charset_valid @charset_valid end |
#encoding_checked ⇒ Object
Returns the value of attribute encoding_checked
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def encoding_checked @encoding_checked end |
#encoding_valid ⇒ Object
Returns the value of attribute encoding_valid
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def encoding_valid @encoding_valid end |
#syntax_checked ⇒ Object
Returns the value of attribute syntax_checked
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def syntax_checked @syntax_checked end |
#syntax_valid ⇒ Object
Returns the value of attribute syntax_valid
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def syntax_valid @syntax_valid end |
#type_checked ⇒ Object
Returns the value of attribute type_checked
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def type_checked @type_checked end |
#type_valid ⇒ Object
Returns the value of attribute type_valid
48 49 50 |
# File 'lib/store/digest/entry.rb', line 48 def type_valid @type_valid end |
Class Method Details
.from(arg) ⇒ Store::Digest::Entry::Flags
Initialize a struct of flags from arbitrary input
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/store/digest/entry.rb', line 59 def from arg # get the length since we use it in a few places len = self.members.size if arg.is_a? Integer tmp = arg.digits(2).first(len) elsif arg.is_a? self # noop return arg elsif arg.is_a? Hash tmp = arg.slice(*self.members).transform_values do |v| !!(v && v != 0) end return self.[](**tmp) elsif arg.respond_to? :to_a tmp = arg.to_a.first(len) else raise ArgumentError, 'Input must be an integer or array' end # append these tmp += [false] * (len - tmp.size) if tmp.size < len # make sure these are true/false tmp.map! { |b| !!(b && b != 0) } # we do this because `new` doesn't do this self.[](*tmp) end |
.to_i(array) ⇒ Integer
Turn an arbitrary Array back into an Integer.
95 96 97 |
# File 'lib/store/digest/entry.rb', line 95 def to_i array array.to_a.reverse.reduce(0) { |acc, b| (acc << 1) | (b ? 1 : 0) } end |