Class: Store::Digest::Entry::Flags

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cacheObject

Returns the value of attribute cache

Returns:

  • (Object)

    the current value of cache



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def cache
  @cache
end

#charset_checkedObject

Returns the value of attribute charset_checked

Returns:

  • (Object)

    the current value of charset_checked



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def charset_checked
  @charset_checked
end

#charset_validObject

Returns the value of attribute charset_valid

Returns:

  • (Object)

    the current value of charset_valid



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def charset_valid
  @charset_valid
end

#encoding_checkedObject

Returns the value of attribute encoding_checked

Returns:

  • (Object)

    the current value of encoding_checked



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def encoding_checked
  @encoding_checked
end

#encoding_validObject

Returns the value of attribute encoding_valid

Returns:

  • (Object)

    the current value of encoding_valid



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def encoding_valid
  @encoding_valid
end

#syntax_checkedObject

Returns the value of attribute syntax_checked

Returns:

  • (Object)

    the current value of syntax_checked



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def syntax_checked
  @syntax_checked
end

#syntax_validObject

Returns the value of attribute syntax_valid

Returns:

  • (Object)

    the current value of syntax_valid



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def syntax_valid
  @syntax_valid
end

#type_checkedObject

Returns the value of attribute type_checked

Returns:

  • (Object)

    the current value of type_checked



48
49
50
# File 'lib/store/digest/entry.rb', line 48

def type_checked
  @type_checked
end

#type_validObject

Returns the value of attribute type_valid

Returns:

  • (Object)

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

Parameters:

Returns:



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.

Parameters:

  • array (Array)

Returns:

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

Instance Method Details

#&(int) ⇒ Object



100
101
102
# File 'lib/store/digest/entry.rb', line 100

def &(int)
  to_i & int.to_i
end

#|(int) ⇒ Object



104
105
106
# File 'lib/store/digest/entry.rb', line 104

def |(int)
  to_i | int.to_i
end