Class: HashMap::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_map/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, options = {}) ⇒ Base

Returns a new instance of Base.



24
25
26
27
# File 'lib/hash_map/base.rb', line 24

def initialize(original, options = {})
  @original = _transforms_input(prepare_input(original))
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/hash_map/base.rb', line 23

def options
  @options
end

#originalObject (readonly)

Returns the value of attribute original.



23
24
25
# File 'lib/hash_map/base.rb', line 23

def original
  @original
end

Class Method Details

.inherited(subclass) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/hash_map/base.rb', line 9

def self.inherited(subclass)
  subclass.extend ToDSL
  return unless self < HashMap::Base
  unless dsl.attributes.empty?
    subclass._set_attributes_from_inheritance(attributes.deep_dup)
  end
end

.map(*args) ⇒ Object



4
5
6
# File 'lib/hash_map/base.rb', line 4

def self.map(*args)
  new(*args).output
end

.only_provided_call(*args) ⇒ Object



17
18
19
20
21
# File 'lib/hash_map/base.rb', line 17

def self.only_provided_call(*args)
  Class.new(self) do
    only_provided_keys
  end.call(*args)
end

Instance Method Details

#[](key) ⇒ Object



42
43
44
# File 'lib/hash_map/base.rb', line 42

def [](key)
  output[key]
end

#mapperObject



29
30
31
# File 'lib/hash_map/base.rb', line 29

def mapper
  @mapper ||= Mapper.new(original, self)
end

#outputObject Also known as: to_h, to_hash, call, execute



33
34
35
# File 'lib/hash_map/base.rb', line 33

def output
  @output ||= _transforms_output(mapper.output)
end