Class: Store::Digest::Object::Flags
- Inherits:
-
Struct
- Object
- Struct
- Store::Digest::Object::Flags
- Defined in:
- lib/store/digest/object.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::Object::Flags
Initialize a struct of flags from arbitrary input.
-
.to_i(array) ⇒ Integer
Turn an arbitrary Array back into an Integer.
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def cache @cache end |
#charset_checked ⇒ Object
Returns the value of attribute charset_checked
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def charset_checked @charset_checked end |
#charset_valid ⇒ Object
Returns the value of attribute charset_valid
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def charset_valid @charset_valid end |
#encoding_checked ⇒ Object
Returns the value of attribute encoding_checked
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def encoding_checked @encoding_checked end |
#encoding_valid ⇒ Object
Returns the value of attribute encoding_valid
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def encoding_valid @encoding_valid end |
#syntax_checked ⇒ Object
Returns the value of attribute syntax_checked
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def syntax_checked @syntax_checked end |
#syntax_valid ⇒ Object
Returns the value of attribute syntax_valid
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def syntax_valid @syntax_valid end |
#type_checked ⇒ Object
Returns the value of attribute type_checked
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def type_checked @type_checked end |
#type_valid ⇒ Object
Returns the value of attribute type_valid
77 78 79 |
# File 'lib/store/digest/object.rb', line 77 def type_valid @type_valid end |
Class Method Details
.from(arg) ⇒ Store::Digest::Object::Flags
Initialize a struct of flags from arbitrary input
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/store/digest/object.rb', line 89 def self.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.
125 126 127 |
# File 'lib/store/digest/object.rb', line 125 def self.to_i array array.to_a.reverse.reduce(0) { |acc, b| (acc << 1) | (b ? 1 : 0) } end |