From b9a9ce389015f39eb089caaa7205ec8c8624cf71 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 28 Jul 2015 15:05:40 -0400 Subject: [PATCH] import from gallery some of the stuff to support single-pageiness feels a bit hacky. ah, well :P --- app/models/neopets_page.rb | 41 ++++++++++++++++++++---- app/views/closet_hangers/index.html.haml | 1 + config/locales/en.yml | 2 ++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/models/neopets_page.rb b/app/models/neopets_page.rb index 52d63310..6144a954 100644 --- a/app/models/neopets_page.rb +++ b/app/models/neopets_page.rb @@ -89,6 +89,9 @@ class NeopetsPage @selectors = params.fetch(:selectors) @parse_id = params.fetch(:parse_id, lambda { |id| id }) @parse_index = params.fetch(:parse_index, lambda { |index| index }) + @has_quantity = params.fetch(:has_quantity, true) + @has_id = params.fetch(:has_id, true) + @has_pages = params.fetch(:has_pages, true) end @@ -112,18 +115,22 @@ class NeopetsPage def find_id(row) - @parse_id.call(element(:item_remove, row)['name']) + @parse_id.call(element(:item_remove, row)['name']).try(:to_i) if @has_id end def find_index(page_selector) - @parse_index.call(element(:selected, page_selector)['value'].to_i) + if @has_pages + @parse_index.call(element(:selected, page_selector)['value'].to_i) + else + 1 + end end def find_items(doc) elements(:items, doc).map do |el| - ItemRef.new(find_id(el).try(:to_i), find_thumbnail_url(el), find_name(el), find_quantity(el)) + ItemRef.new(find_id(el), find_thumbnail_url(el), find_name(el), find_quantity(el)) end end @@ -142,12 +149,16 @@ class NeopetsPage def find_page_selector(doc) - element(:page_select, doc) + element(:page_select, doc) if @has_pages end def find_quantity(row) - element(:item_quantity, row).text.to_i + if @has_quantity + element(:item_quantity, row).text.to_i + else + 1 + end end @@ -157,7 +168,11 @@ class NeopetsPage def find_page_count(page_selector) - page_selector.css('option').size + if @has_pages + page_selector.css('option').size + else + 1 + end end end @@ -224,6 +239,20 @@ class NeopetsPage }, parse_index: lambda { |offset| offset / 30 + 1 } ) + ), + 'gallery' => Type.new( + get_name: lambda { I18n.translate('neopets_page_import_tasks.names.gallery') }, + get_url: lambda { |index| "http://www.neopets.com/gallery/index.phtml?view=all" }, + parser: Parser.new( + selectors: { + items: "form[name=gallery_form] td[valign=top]", + item_thumbnail: "img", + item_name: "b" + }, + has_quantity: false, + has_id: false, + has_pages: false + ) ) } diff --git a/app/views/closet_hangers/index.html.haml b/app/views/closet_hangers/index.html.haml index 24667e87..7fb0fa64 100644 --- a/app/views/closet_hangers/index.html.haml +++ b/app/views/closet_hangers/index.html.haml @@ -50,6 +50,7 @@ = link_to t('.import_from.closet'), new_neopets_page_import_task_path(page_type: 'closet', expected_index: 1) = link_to t('.import_from.safety_deposit'), new_neopets_page_import_task_path(page_type: 'safety_deposit', expected_index: 1) + = link_to t('.import_from.gallery'), new_neopets_page_import_task_path(page_type: 'gallery', expected_index: 1) = link_to t('.import_from.neopets_user'), new_neopets_user_path = link_to t('.export_to.petpage'), petpage_user_closet_hangers_path(@user) diff --git a/config/locales/en.yml b/config/locales/en.yml index f161f07b..f339187c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -116,6 +116,7 @@ en: import_from: closet: Import from closet safety_deposit: Import from SDB + gallery: Import from gallery neopets_user: Import from pets export_to: petpage: Export to petpage @@ -438,6 +439,7 @@ en: names: closet: closet safety_deposit: safety deposit + gallery: gallery new: title: Import from %{name}, Page %{index}