Class: Stew::Store::App

Inherits:
Object
  • Object
show all
Defined in:
lib/stew/store/app.rb

Overview

An application in the Steam Store Initialized from the contents of a web request to the Steam store app page

Instance Method Summary collapse

Constructor Details

#initialize(response, id) ⇒ App

Returns a new instance of App.



9
10
11
12
# File 'lib/stew/store/app.rb', line 9

def initialize(response, id)
  @document = Nokogiri::HTML(response)
  @id = id
end

Instance Method Details

#capsule_imageObject



43
44
45
# File 'lib/stew/store/app.rb', line 43

def capsule_image
  "http://cdn2.steampowered.com/v/gfx/apps/#{@id}/capsule_sm_120.jpg"
end

#developerObject



31
32
33
# File 'lib/stew/store/app.rb', line 31

def developer
  App.content_or_nil @document.at_xpath("//a[contains(@href, 'developer')]")
end

#dlc?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/stew/store/app.rb', line 51

def dlc?
  !@document.css("div.game_area_dlc_bubble").empty?
end

#dlc_app_idObject



55
56
57
58
59
# File 'lib/stew/store/app.rb', line 55

def dlc_app_id
  return nil unless dlc?
  #Close your eyes...
  @document.at_css("div.game_area_dlc_bubble").at_css('a').attributes['href'].value[/\d+/].to_i
end

#free?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/stew/store/app.rb', line 75

def free?
  offers.count == 0
end

#genresObject



27
28
29
# File 'lib/stew/store/app.rb', line 27

def genres
  @document.css("div.glance_details").css("a").map {|node| node.content}
end

#header_imageObject



39
40
41
# File 'lib/stew/store/app.rb', line 39

def header_image
  App.src_or_nil @document.at_css('img.game_header_image')
end

#indie?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/stew/store/app.rb', line 61

def indie?
  genres.include? 'Indie'
end

#nameObject



18
19
20
# File 'lib/stew/store/app.rb', line 18

def name
  App.content_or_nil @document.at_css("div.apphub_AppName")
end

#offersObject



47
48
49
# File 'lib/stew/store/app.rb', line 47

def offers
  @offers ||= AppOffers.new @document.css("div.game_area_purchase_game")
end

#priceObject



65
66
67
68
# File 'lib/stew/store/app.rb', line 65

def price
  return nil if free?
  first_offer.price
end

#publisherObject



35
36
37
# File 'lib/stew/store/app.rb', line 35

def publisher
  App.content_or_nil @document.at_xpath("//a[contains(@href, 'publisher')]")
end

#regular_priceObject



70
71
72
73
# File 'lib/stew/store/app.rb', line 70

def regular_price
  return nil if free?
  first_offer.regular_price
end

#release_dateObject



22
23
24
25
# File 'lib/stew/store/app.rb', line 22

def release_date
  node = @document.at_xpath("//b[.='Release Date:']")
  node && Date.parse(node.next.content)
end

#scoreObject



14
15
16
# File 'lib/stew/store/app.rb', line 14

def score
  score_section[0] && score_from_score_section
end