Module: ButterSand::API::Events

Included in:
Client
Defined in:
lib/butter_sand/api/events.rb

Constant Summary collapse

PATH_SAIJI =
'/contents/shop/saiji/'

Instance Method Summary collapse

Instance Method Details

#allArray<ButterSand::Event>

Returns list of all event information listed on the page. When there is no event information to be held, returns empty array.

Returns:



13
14
15
# File 'lib/butter_sand/api/events.rb', line 13

def all
  ButterSand::Parser.to_array(get(PATH_SAIJI)).map {|event| ButterSand::Event.new(event)}
end

#ends_todayArray<ButterSand::Event>

Returns list of event information that ends today. When there is no corresponding data, returns empty array.

Returns:



34
35
36
# File 'lib/butter_sand/api/events.rb', line 34

def ends_today
  all.select {|event| event.ends == (@date_for_test || Date.today)}
end

#find_by_prefecture(name) ⇒ Array<ButterSand::Event>

Returns list of event information selected with given prefecture name. When there is no corresponding data, returns empty array.

Parameters:

  • name (String)

    prefecture name

Returns:

Raises:

  • (ArgumentError)

    Error raised when supplied prefecture name is not valid



43
44
45
46
# File 'lib/butter_sand/api/events.rb', line 43

def find_by_prefecture(name)
  raise ArgumentError , 'Illegal argument' unless name.kind_of? String
  all.select {|event| event.prefecture == name}
end

#on_saleArray<ButterSand::Event>

Returns list of event information being held. When there is no corresponding data, returns empty array.

Returns:



20
21
22
# File 'lib/butter_sand/api/events.rb', line 20

def on_sale
  all.select {|event| (event.starts..event.ends) === (@date_for_test || Date.today)}
end

#starts_todayArray<ButterSand::Event>

Returns list of event information that starts today. When there is no corresponding data, returns empty array.

Returns:



27
28
29
# File 'lib/butter_sand/api/events.rb', line 27

def starts_today
  all.select {|event| event.starts == (@date_for_test || Date.today)}
end