Class: Store::Digest::Object::Flags

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Attribute Details

#cacheObject

Returns the value of attribute cache

Returns:

  • (Object)

    the current value of cache



95
96
97
# File 'lib/store/digest/object.rb', line 95

def cache
  @cache
end

#charset_checkedObject

Returns the value of attribute charset_checked

Returns:

  • (Object)

    the current value of charset_checked



95
96
97
# File 'lib/store/digest/object.rb', line 95

def charset_checked
  @charset_checked
end

#charset_validObject

Returns the value of attribute charset_valid

Returns:

  • (Object)

    the current value of charset_valid



95
96
97
# File 'lib/store/digest/object.rb', line 95

def charset_valid
  @charset_valid
end

#encoding_checkedObject

Returns the value of attribute encoding_checked

Returns:

  • (Object)

    the current value of encoding_checked



95
96
97
# File 'lib/store/digest/object.rb', line 95

def encoding_checked
  @encoding_checked
end

#encoding_validObject

Returns the value of attribute encoding_valid

Returns:

  • (Object)

    the current value of encoding_valid



95
96
97
# File 'lib/store/digest/object.rb', line 95

def encoding_valid
  @encoding_valid
end

#syntax_checkedObject

Returns the value of attribute syntax_checked

Returns:

  • (Object)

    the current value of syntax_checked



95
96
97
# File 'lib/store/digest/object.rb', line 95

def syntax_checked
  @syntax_checked
end

#syntax_validObject

Returns the value of attribute syntax_valid

Returns:

  • (Object)

    the current value of syntax_valid



95
96
97
# File 'lib/store/digest/object.rb', line 95

def syntax_valid
  @syntax_valid
end

#type_checkedObject

Returns the value of attribute type_checked

Returns:

  • (Object)

    the current value of type_checked



95
96
97
# File 'lib/store/digest/object.rb', line 95

def type_checked
  @type_checked
end

#type_validObject

Returns the value of attribute type_valid

Returns:

  • (Object)

    the current value of 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

Parameters:

Returns:



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.

Parameters:

  • array (Array)

Returns:

  • (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