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
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def cache @cache end |
#charset_checked ⇒ Object
Returns the value of attribute charset_checked
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def charset_checked @charset_checked end |
#charset_valid ⇒ Object
Returns the value of attribute charset_valid
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def charset_valid @charset_valid end |
#encoding_checked ⇒ Object
Returns the value of attribute encoding_checked
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def encoding_checked @encoding_checked end |
#encoding_valid ⇒ Object
Returns the value of attribute encoding_valid
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def encoding_valid @encoding_valid end |
#syntax_checked ⇒ Object
Returns the value of attribute syntax_checked
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def syntax_checked @syntax_checked end |
#syntax_valid ⇒ Object
Returns the value of attribute syntax_valid
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def syntax_valid @syntax_valid end |
#type_checked ⇒ Object
Returns the value of attribute type_checked
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def type_checked @type_checked end |
#type_valid ⇒ Object
Returns the value of attribute type_valid
95 96 97 |
# File 'lib/store/digest/object.rb', line 95 def type_valid @type_valid end |
Class Method Details
.from(arg) ⇒ Store::Digest::Object::Flags
Initialize a struct of flags from arbitrary input
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/store/digest/object.rb', line 107 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.
143 144 145 |
# File 'lib/store/digest/object.rb', line 143 def self.to_i array array.to_a.reverse.reduce(0) { |acc, b| (acc << 1) | (b ? 1 : 0) } end |