Class: SeeingIsBelieving::Binary::Marker

Inherits:
HashStruct
  • Object
show all
Defined in:
lib/seeing_is_believing/binary/data_structures.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HashStruct

#==, #[], #each, #fetch, #hash, #initialize, inspect, #inspect, #key?, #keys, #merge, #pretty_print, #to_hash, #values

Constructor Details

This class inherits a constructor from SeeingIsBelieving::HashStruct

Class Method Details

.to_regex(string) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/seeing_is_believing/binary/data_structures.rb', line 14

def self.to_regex(string)
  return string if string.kind_of? Regexp
  flag_to_bit = {
    'i' => 0b001,
    'x' => 0b010,
    'm' => 0b100
  }
  string =~ %r{\A/(.*)/([mxi]*)\Z}
  body  = $1 || string
  flags = ($2 || "").each_char.inject(0) { |bits, flag| bits | flag_to_bit[flag] }
  Regexp.new body, flags
end

Instance Method Details

#[]=(key, value) ⇒ Object



30
31
32
33
# File 'lib/seeing_is_believing/binary/data_structures.rb', line 30

def []=(key, value)
  value = Marker.to_regex(value) if key == :regex
  super key, value
end