Class: Subscene::SubtitleResult

Inherits:
Object
  • Object
show all
Defined in:
lib/subscene/subtitle_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ SubtitleResult

Returns a new instance of SubtitleResult


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/subscene/subtitle_result.rb', line 6

def initialize(attributes)
  @attributes = attributes

  @id      = @attributes[:id]
  @name    = @attributes[:name]
  @url     = @attributes[:url]
  @lang    = @attributes[:lang]
  @user    = @attributes[:user]
  @user_id = @attributes[:user_id]
  @comment = @attributes[:comment]
  @files_count = @attributes[:files_count]
  @hearing_impaired = @attributes[:hearing_impaired]
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def attributes
  @attributes
end

#commentObject

Returns the value of attribute comment


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def comment
  @comment
end

#files_countObject

Returns the value of attribute files_count


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def files_count
  @files_count
end

#hearing_impairedObject

Returns the value of attribute hearing_impaired


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def hearing_impaired
  @hearing_impaired
end

#idObject

Returns the value of attribute id


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def id
  @id
end

#langObject

Returns the value of attribute lang


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def lang
  @lang
end

#nameObject

Returns the value of attribute name


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def name
  @name
end

#urlObject

Returns the value of attribute url


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def url
  @url
end

#userObject

Returns the value of attribute user


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def user
  @user
end

#user_idObject

Returns the value of attribute user_id


3
4
5
# File 'lib/subscene/subtitle_result.rb', line 3

def user_id
  @user_id
end

Class Method Details

.build(html) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/subscene/subtitle_result.rb', line 20

def self.build(html)
  subtitle_url = (html.css("td.a1 a").attribute("href").value rescue nil)

  new({
    id:      (subtitle_url.match(/\d+$/).to_s rescue nil),
    name:    (html.css("td.a1 span[2]").text.strip rescue nil),
    url:     subtitle_url,
    lang:    (html.css("td.a1 span[1]").text.strip rescue nil),
    user:    (html.css("td.a5").text.strip rescue nil),
    user_id: (html.css("td.a5 a").attribute("href").value.match(/\d+/).to_s rescue nil),
    comment: (html.css("td.a6").text.strip rescue nil),
    files_count: (html.css("td.a3").text.to_i rescue nil),
    hearing_impaired: html.at_css("td.a40").nil?
  })
end