Class: ParsableHash::HashStrategy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/parsable_hash/hash_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy, origin_hash = nil) ⇒ HashStrategy

Returns a new instance of HashStrategy.



8
9
10
11
12
13
# File 'lib/parsable_hash/hash_strategy.rb', line 8

def initialize(strategy, origin_hash = nil)
  @hash = prepare(strategy)
  self.origin_hash = origin_hash

  clean_for_hash!(origin_hash) unless origin_hash.nil?
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/parsable_hash/hash_strategy.rb', line 5

def hash
  @hash
end

#origin_hashObject

Returns the value of attribute origin_hash.



6
7
8
# File 'lib/parsable_hash/hash_strategy.rb', line 6

def origin_hash
  @origin_hash
end

Instance Method Details

#clean_for_hash!(value_hash) ⇒ Object



19
20
21
# File 'lib/parsable_hash/hash_strategy.rb', line 19

def clean_for_hash!(value_hash)
  @hash = clean_pairs(@hash, value_hash)
end

#each(&block) ⇒ Object



15
16
17
# File 'lib/parsable_hash/hash_strategy.rb', line 15

def each(&block)
  hash.each { |strategy| yield strategy }
end