Class: AhlScraper::Resource

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ahl_scraper/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, opts = {}) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
# File 'lib/ahl_scraper/resource.rb', line 7

def initialize(raw_data, opts = {})
  @raw_data = raw_data
  @opts = opts
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/ahl_scraper/resource.rb', line 22

def [](key)
  values[key.to_sym]
end

#each(&blk) ⇒ Object



34
35
36
# File 'lib/ahl_scraper/resource.rb', line 34

def each(&blk)
  values.each(&blk)
end

#inspectObject



18
19
20
# File 'lib/ahl_scraper/resource.rb', line 18

def inspect
  "#<#{self.class.to_s.split('::').last}:0x#{object_id.to_s(16)} #{values}>"
end

#keysObject



26
27
28
# File 'lib/ahl_scraper/resource.rb', line 26

def keys
  values.keys
end

#to_json(*_opts) ⇒ Object



30
31
32
# File 'lib/ahl_scraper/resource.rb', line 30

def to_json(*_opts)
  JSON.generate(values)
end

#valuesObject



12
13
14
15
16
# File 'lib/ahl_scraper/resource.rb', line 12

def values
  @values ||= (self.class.instance_methods(false) - %i[to_json inspect each keys [] values]).map do |m|
    [m, send(m)]
  end.to_h.transform_keys(&:to_sym)
end