forked from OpenNeo/impress
import from gallery
some of the stuff to support single-pageiness feels a bit hacky. ah, well :P
This commit is contained in:
parent
954866a3d3
commit
b9a9ce3890
3 changed files with 38 additions and 6 deletions
|
@ -89,6 +89,9 @@ class NeopetsPage
|
||||||
@selectors = params.fetch(:selectors)
|
@selectors = params.fetch(:selectors)
|
||||||
@parse_id = params.fetch(:parse_id, lambda { |id| id })
|
@parse_id = params.fetch(:parse_id, lambda { |id| id })
|
||||||
@parse_index = params.fetch(:parse_index, lambda { |index| index })
|
@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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,18 +115,22 @@ class NeopetsPage
|
||||||
|
|
||||||
|
|
||||||
def find_id(row)
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
def find_index(page_selector)
|
def find_index(page_selector)
|
||||||
|
if @has_pages
|
||||||
@parse_index.call(element(:selected, page_selector)['value'].to_i)
|
@parse_index.call(element(:selected, page_selector)['value'].to_i)
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def find_items(doc)
|
def find_items(doc)
|
||||||
elements(:items, doc).map do |el|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -142,12 +149,16 @@ class NeopetsPage
|
||||||
|
|
||||||
|
|
||||||
def find_page_selector(doc)
|
def find_page_selector(doc)
|
||||||
element(:page_select, doc)
|
element(:page_select, doc) if @has_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def find_quantity(row)
|
def find_quantity(row)
|
||||||
|
if @has_quantity
|
||||||
element(:item_quantity, row).text.to_i
|
element(:item_quantity, row).text.to_i
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +168,11 @@ class NeopetsPage
|
||||||
|
|
||||||
|
|
||||||
def find_page_count(page_selector)
|
def find_page_count(page_selector)
|
||||||
|
if @has_pages
|
||||||
page_selector.css('option').size
|
page_selector.css('option').size
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,6 +239,20 @@ class NeopetsPage
|
||||||
},
|
},
|
||||||
parse_index: lambda { |offset| offset / 30 + 1 }
|
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
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.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.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('.import_from.neopets_user'), new_neopets_user_path
|
||||||
= link_to t('.export_to.petpage'), petpage_user_closet_hangers_path(@user)
|
= link_to t('.export_to.petpage'), petpage_user_closet_hangers_path(@user)
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,7 @@ en:
|
||||||
import_from:
|
import_from:
|
||||||
closet: Import from closet
|
closet: Import from closet
|
||||||
safety_deposit: Import from SDB
|
safety_deposit: Import from SDB
|
||||||
|
gallery: Import from gallery
|
||||||
neopets_user: Import from pets
|
neopets_user: Import from pets
|
||||||
export_to:
|
export_to:
|
||||||
petpage: Export to petpage
|
petpage: Export to petpage
|
||||||
|
@ -438,6 +439,7 @@ en:
|
||||||
names:
|
names:
|
||||||
closet: closet
|
closet: closet
|
||||||
safety_deposit: safety deposit
|
safety_deposit: safety deposit
|
||||||
|
gallery: gallery
|
||||||
|
|
||||||
new:
|
new:
|
||||||
title: Import from %{name}, Page %{index}
|
title: Import from %{name}, Page %{index}
|
||||||
|
|
Loading…
Reference in a new issue