Class: R18Client::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/r18_client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#successObject (readonly)

Returns the value of attribute success.



9
10
11
# File 'lib/r18_client/client.rb', line 9

def success
  @success
end

Instance Method Details

#castObject



33
34
35
# File 'lib/r18_client/client.rb', line 33

def cast
  @doc.css('.product-actress-list [itemprop="name"]').map(&:content)
end

#coverObject



46
47
48
# File 'lib/r18_client/client.rb', line 46

def cover
  @doc.at_css('.detail-single-picture img').attr('src')
end

#genresObject



42
43
44
# File 'lib/r18_client/client.rb', line 42

def genres
  @doc.css('[itemprop="genre"]').map { |el| el.content.strip }
end

#load(code) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/r18_client/client.rb', line 11

def load(code)
  response = RestClient.get(HOST, {params: {searchword: code}}).body
  @doc = Nokogiri::HTML(response)

  if @doc.text.include?('Unable to find related item for')
    @success = false
  else
    url = @doc.at_css('.cmn-list-product01 a').attr('href')
    @doc = Nokogiri::HTML(RestClient.get(url).body)
    @success = true
  end
end

#release_dateObject



37
38
39
40
# File 'lib/r18_client/client.rb', line 37

def release_date
  date = DateTime.parse @doc.at_css('[itemprop="dateCreated"]').content
  date.strftime '%Y-%m-%d'
end

#titleObject



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

def title
  title = @doc.at_css('.product-details-page cite').content
  if self.cast.length == 1
    name = self.cast[0].split.join(' ')
    title = title.reverse.sub(name.reverse, '').reverse
  end
  title.strip
end