Class: WonderScrape::Scrapers::MFC::ItemParser

Inherits:
Object
  • Object
show all
Defined in:
lib/wonder_scrape/scrapers/mfc/item_parser.rb

Constant Summary collapse

DUPLICATE_FIELD_NAMES =
{
  'Artist' => 'Artists',
  'Character' => 'Characters',
  'Classification' => 'Classifications',
  'Company' => 'Companies',
  'Event' => 'Events',
  'Material' => 'Materials',
  'Origin' => 'Origins',
  'Release date' => 'Release dates'
}.freeze
VALID_FIELD_NAMES =
[
  'Title',
  'Artists',
  'Category',
  'Characters',
  'Classifications',
  'Companies',
  'Events',
  'JAN',
  'Materials',
  'Numbering',
  'Origins',
  'Price',
  'Release dates',
  'Scale & Dimensions',
  'Various',
  'Version',
  'Images'
].freeze
ID_SELECTOR =
'#content #ariadne > a.current'
TITLE_SELECTOR =
'#content h1 span.headline'
FIELD_ELEMENTS_SELECTOR =
'#content .data > .form > .form-field'
FIELD_NAME_SELECTOR =
'.form-label'
FIELD_CONTENT_SELECTOR =
'.form-input'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(writer, recorder, item_html) ⇒ ItemParser

Returns a new instance of ItemParser.



53
54
55
56
57
58
# File 'lib/wonder_scrape/scrapers/mfc/item_parser.rb', line 53

def initialize(writer, recorder, item_html)
  @writer = writer
  @recorder = recorder
  @item_html = item_html
  @unexpected_fields = []
end

Class Method Details

.parse(writer, recorder) ⇒ Object



46
47
48
49
50
51
# File 'lib/wonder_scrape/scrapers/mfc/item_parser.rb', line 46

def self.parse(writer, recorder)
  proc do |item_html_text|
    item_html = ::Nokogiri::HTML(item_html_text)
    new(writer, recorder, item_html).parse
  end
end

Instance Method Details

#parseObject



60
61
62
63
64
65
66
67
68
# File 'lib/wonder_scrape/scrapers/mfc/item_parser.rb', line 60

def parse
  result = {}
  result['Title'] = parsed_title
  result.merge! parsed_fields
  result['Images'] = parsed_images

  writer.write(result)
  recorder.increment_items_scraped(result)
end