Class: CbNitride::PublicHasher

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

Constant Summary collapse

BASE_URL =
"http://www.previewsworld.com"
DIAMOND_NUMBER_SEARCH_PATH =
"/Home/1/1/71/952?stockItemID="
SEARCH_URL =
BASE_URL + DIAMOND_NUMBER_SEARCH_PATH
IMAGE_CLASS =
"a.FancyPopupImage"
CONTAINER_CLASS =
".StockCode"
TITLE_CLASS =
".StockCodeDescription"
PUBLISHER_CLASS =
".StockCodePublisher"
CREATOR_CLASS =
".StockCodeCreators"
DESCRIPTION_CLASS =
".PreviewsHtml"
RELEASE_CLASS =
".StockCodeInShopsDate"
PRICE_CLASS =
".StockCodeSrp"

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 = Mechanize.new) ⇒ PublicHasher

Returns a new instance of PublicHasher.



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

def initialize(diamond_number, agent = Mechanize.new)
  @diamond_number = diamond_number
  @agent = agent
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



8
9
10
# File 'lib/cb_nitride/public_hasher.rb', line 8

def agent
  @agent
end

#container_classObject (readonly)

Returns the value of attribute container_class.



8
9
10
# File 'lib/cb_nitride/public_hasher.rb', line 8

def container_class
  @container_class
end

#diamond_numberObject (readonly)

Returns the value of attribute diamond_number.



8
9
10
# File 'lib/cb_nitride/public_hasher.rb', line 8

def diamond_number
  @diamond_number
end

#image_classObject (readonly)

Returns the value of attribute image_class.



8
9
10
# File 'lib/cb_nitride/public_hasher.rb', line 8

def image_class
  @image_class
end

#search_urlObject (readonly)

Returns the value of attribute search_url.



8
9
10
# File 'lib/cb_nitride/public_hasher.rb', line 8

def search_url
  @search_url
end

Class Method Details

.item(diamond_number) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cb_nitride/public_hasher.rb', line 24

def self.item(diamond_number)
  item = new(diamond_number)
  if item.valid_diamond_number?
    item.spawn_item
  else
    return nil
  end
end

Instance Method Details

#spawn_itemObject



38
39
40
# File 'lib/cb_nitride/public_hasher.rb', line 38

def spawn_item
 DiamondItem.new(branded_hash)
end

#valid_diamond_number?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/cb_nitride/public_hasher.rb', line 42

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