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

Returns the category of the program.

Returns:

  • (String)

    the category of the program.



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

def category
  @category
end

#channel_idNumeric

Returns the ID of the channel.

Returns:

  • (Numeric)

    the ID of the channel.



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

def channel_id
  @channel_id
end

#descriptionString

Returns the description of the program.

Returns:

  • (String)

    the description of the program.



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

def description
  @description
end

#idNumeric (readonly)

Returns the id of the program.

Returns:

  • (Numeric)

    the id of the program.



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

def id
  @id
end

#original_titleString

Returns the original non-localized title of the program.

Returns:

  • (String)

    the original non-localized title of the program.



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

def original_title
  @original_title
end

#production_countryString

Returns the production country of the program.

Returns:

  • (String)

    the production country of the program.



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

def production_country
  @production_country
end

#production_yearNumeric

Returns the year of production of the program.

Returns:

  • (Numeric)

    the year of production of the program.



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

def production_year
  @production_year
end

#series_idNumeric

Returns a unique series id if the program is a series.

Returns:

  • (Numeric)

    a unique series id if the program is a series.



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

def series_id
  @series_id
end

#series_infoHash?

Returns episode and season information if the program is a series.

Returns:

  • (Hash, nil)

    episode and season information if the program is a series.



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

def series_info
  @series_info
end

#start_timeDateTime

Returns the time the program starts at.

Returns:

  • (DateTime)

    the time the program starts at.



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

def start_time
  @start_time
end

#stop_timeDateTime

Returns the time the program ends at.

Returns:

  • (DateTime)

    the time the program ends at.



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

def stop_time
  @stop_time
end

#teaserString

Returns the teaser text of the program.

Returns:

  • (String)

    the teaser text of the program.



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

def teaser
  @teaser
end

#titleString (readonly)

Returns the title of the program.

Returns:

  • (String)

    the title of the program.



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

def title
  @title
end

#urlString

Returns a URL to where the user can see more information about the program.

Returns:

  • (String)

    a URL to where the user can see more information about the program.



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.

Parameters:

  • json (Hash)

    Parsed JSON object

Returns:

  • (Program, nil)

    program if the given ‘json` object has an `id` and a `title` attribute, nil otherwise.



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.

Parameters:

  • json (Hash)

    Parsed 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