Class: TVTid::Program

Inherits:
Object
  • Object
show all
Defined in:
library/tvtid/program.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, title) ⇒ Program

Constructs a new `Program` with an `id` and a `title`.


35
36
37
38
# File 'library/tvtid/program.rb', line 35

def initialize id, title
  @id = id
  @title = title
end

Instance Attribute Details

#categoryString


17
18
19
# File 'library/tvtid/program.rb', line 17

def category
  @category
end

#channel_idNumeric


15
16
17
# File 'library/tvtid/program.rb', line 15

def channel_id
  @channel_id
end

#descriptionString


19
20
21
# File 'library/tvtid/program.rb', line 19

def description
  @description
end

#idNumeric (readonly)


4
5
6
# File 'library/tvtid/program.rb', line 4

def id
  @id
end

#original_titleString


21
22
23
# File 'library/tvtid/program.rb', line 21

def original_title
  @original_title
end

#production_countryString


25
26
27
# File 'library/tvtid/program.rb', line 25

def production_country
  @production_country
end

#production_yearNumeric


23
24
25
# File 'library/tvtid/program.rb', line 23

def production_year
  @production_year
end

#series_idNumeric


29
30
31
# File 'library/tvtid/program.rb', line 29

def series_id
  @series_id
end

#series_infoHash?


32
33
34
# File 'library/tvtid/program.rb', line 32

def series_info
  @series_info
end

#start_timeDateTime


8
9
10
# File 'library/tvtid/program.rb', line 8

def start_time
  @start_time
end

#stop_timeDateTime


10
11
12
# File 'library/tvtid/program.rb', line 10

def stop_time
  @stop_time
end

#teaserString


27
28
29
# File 'library/tvtid/program.rb', line 27

def teaser
  @teaser
end

#titleString (readonly)


6
7
8
# File 'library/tvtid/program.rb', line 6

def title
  @title
end

#urlString


13
14
15
# File 'library/tvtid/program.rb', line 13

def url
  @url
end

Class Method Details

.from_json(json) ⇒ Program?

Constructs a `Program` from a json object.


62
63
64
65
66
67
68
# File 'library/tvtid/program.rb', line 62

def self.from_json json
  return nil unless json['id'] and json['title']

  Program.new(json['id'], json['title']).tap do |program|
    program.parse_json! json
  end
end

Instance Method Details

#parse_json!(json) ⇒ Object

Updates the program information from a json object.


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'library/tvtid/program.rb', line 43

def parse_json! json
  @start_time = Time.at(json['start']).to_datetime
  @stop_time = Time.at(json['stop']).to_datetime
  @url = json['url'] if json.key?('url')
  @channel_id = json['channelId'] if json.key?('channelId')
  @category = json['category'] if json.key?('category')
  @description = json['desc'] if json.key?('desc')
  @production_year = json['prodYear'] if json.key?('prodYear')
  @production_country = json['prodCountry'] if json.key?('prodCountry')
  @teaser = json['teaser'] if json.key?('teaser')
  @series_id = json['series_id'] if json.key?('seriesId')
  @series_info = json['series'] if json.key?('series')
end