Class: HttpPage
Instance Attribute Summary
#_, #stylesheet
Instance Method Summary
collapse
#alert, #build_layout, #compile_styles, #history, layout, #name, #navbar, new, #repaint, #setup_wrap, #title, #title=, #view, #view=
#emit, #off, #on
Constructor Details
Returns a new instance of HttpPage.
3
4
5
6
7
8
9
|
# File 'app/pages/http_page.rb', line 3
def initialize
@search = first('#search-form input')
@result = first('img#result')
@locker = Locker.new
first('#search-form button').on(:tap) { search }
end
|
Instance Method Details
#parse_first_image_url(html) ⇒ Object
29
30
31
|
# File 'app/pages/http_page.rb', line 29
def parse_first_image_url(html)
html.scan(/imgurl=(http:\/\/[^&]+)/)[0][0]
end
|
#search ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'app/pages/http_page.rb', line 11
def search
@search.hide_keyboard
@locker.show
UnderOs::HTTP.get search_url do |response|
@result.load parse_first_image_url(response.body) do
@locker.hide
end
end
end
|
#search_url ⇒ Object
22
23
24
25
26
27
|
# File 'app/pages/http_page.rb', line 22
def search_url
query = @search.value
query = 'puppy' if query.empty?
"https://www.google.com.au/search?q=#{query}&source=lnms&tbm=isch"
end
|