Class: Nytimes::Articles::FacetHash

Inherits:
Object
  • Object
show all
Defined in:
lib/nytimes_articles/facet_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ FacetHash

Returns a new instance of FacetHash.



4
5
6
# File 'lib/nytimes_articles/facet_hash.rb', line 4

def initialize(hash)
  @facets = hash
end

Class Method Details

.init_from_api(hash) ⇒ Object



21
22
23
# File 'lib/nytimes_articles/facet_hash.rb', line 21

def self.init_from_api(hash)
  new(hash)
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nytimes_articles/facet_hash.rb', line 8

def [](key)
  case key
  when Symbol
    key = Facet.symbol_name(key)
  when String
    # do nothing
  else
    raise ArgumentError, "Argument to facets hash must be a symbol or string name"
  end
  
  @facets[key]
end