Class: CbNitride::PrivateHasher

Inherits:
Object
  • Object
show all
Includes:
HasherMethods
Defined in:
lib/cb_nitride/private_hasher.rb

Constant Summary collapse

BASE_URL =
"https://retailerservices.diamondcomics.com"
DIAMOND_NUMBER_SEARCH_PATH =
"/ShoppingList/AddItem/"
SEARCH_URL =
BASE_URL + DIAMOND_NUMBER_SEARCH_PATH
IMAGE_CLASS =
'a.ImagePopup'
TITLE_CLASS =
'.ItemDetails_ItemName'
PUBLISHER_CLASS =
'.ItemDetails_Publisher'
CREATOR_CLASS =
'.ItemDetails_Creator'
DESCRIPTION_CLASS =
'.ItemDetails_Description'
CONTAINER_CLASS =
'.PopupContent'

Instance Attribute Summary collapse

Attributes included from HasherMethods

#error_array

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasherMethods

#clean_date_string, #clean_price_float, #find_text_with, #get_image_url

Constructor Details

#initialize(diamond_number, agent = DiamondLogin.agent) ⇒ PrivateHasher

Returns a new instance of PrivateHasher.



28
29
30
31
# File 'lib/cb_nitride/private_hasher.rb', line 28

def initialize(diamond_number, agent = DiamondLogin.agent)
  @diamond_number = diamond_number
  @agent = agent
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



5
6
7
# File 'lib/cb_nitride/private_hasher.rb', line 5

def agent
  @agent
end

#container_classObject (readonly)

Returns the value of attribute container_class.



5
6
7
# File 'lib/cb_nitride/private_hasher.rb', line 5

def container_class
  @container_class
end

#diamond_numberObject (readonly)

Returns the value of attribute diamond_number.



5
6
7
# File 'lib/cb_nitride/private_hasher.rb', line 5

def diamond_number
  @diamond_number
end

#image_classObject (readonly)

Returns the value of attribute image_class.



5
6
7
# File 'lib/cb_nitride/private_hasher.rb', line 5

def image_class
  @image_class
end

#search_urlObject (readonly)

Returns the value of attribute search_url.



5
6
7
# File 'lib/cb_nitride/private_hasher.rb', line 5

def search_url
  @search_url
end

Class Method Details

.item(diamond_number, agent = DiamondLogin.agent) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/cb_nitride/private_hasher.rb', line 19

def self.item(diamond_number, agent = DiamondLogin.agent)
  item = new(diamond_number, agent)
  if item.valid_diamond_number?
    item.spawn_item
  else
    return NullItem.new(diamond_number)
  end
end

Instance Method Details

#spawn_itemObject



33
34
35
# File 'lib/cb_nitride/private_hasher.rb', line 33

def spawn_item
  DiamondItem.new(branded_hash)
end

#valid_diamond_number?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/cb_nitride/private_hasher.rb', line 37

def valid_diamond_number?
  if item_page.css(CONTAINER_CLASS).empty?
    return false
  else
    return true
  end
end