Class: Jani::FromJson::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/jani/from_json/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_data: {}.to_s) ⇒ Builder

Returns a new instance of Builder.



10
11
12
# File 'lib/jani/from_json/builder.rb', line 10

def initialize(json_data: {}.to_s)
  @json_data = json_data
end

Instance Attribute Details

#json_dataObject

Returns the value of attribute json_data.



8
9
10
# File 'lib/jani/from_json/builder.rb', line 8

def json_data
  @json_data
end

Instance Method Details

#new_loading_bannerObject



29
30
31
32
# File 'lib/jani/from_json/builder.rb', line 29

def new_loading_banner
  return Jani::FromJson::Banner.new unless hashed_data["loading_banner"]
  Jani::FromJson::Banner.new.tap { |b| b.image_url = hashed_data["loading_banner"]["image_url"] }
end

#new_movieObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jani/from_json/builder.rb', line 14

def new_movie
  Jani::FromJson::Movie.new.tap do |m|
    m.uuid = hashed_data["uuid"]
    m.frame_width = hashed_data["frame_width"]
    m.frame_height = hashed_data["frame_height"]
    m.fps = hashed_data["fps"]
    m.pixel_ratio = hashed_data["pixel_ratio"]
    m.loading_banner = new_loading_banner
    m.postroll_banner = new_postroll_banner
    m.strips = new_strips
    m.tracking_events = new_tracking_events
    m.conversion_status = hashed_data["conversion_status"]
  end
end

#new_postroll_bannerObject



34
35
36
37
38
39
40
# File 'lib/jani/from_json/builder.rb', line 34

def new_postroll_banner
  return Jani::FromJson::Banner.new unless hashed_data["postroll_banner"]
  Jani::FromJson::Banner.new.tap do |b|
    b.image_url = hashed_data["postroll_banner"]["image_url"]
    b.url = hashed_data["postroll_banner"]["url"]
  end
end

#new_stripsObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/jani/from_json/builder.rb', line 42

def new_strips
  return [] unless hashed_data["strips"]
  hashed_data["strips"].map do |strip_data|
    Jani::FromJson::Strip.new.tap do |s|
      s.index = strip_data["index"]
      s.image_url = strip_data["image_url"]
      s.frames_count = strip_data["frames_count"]
    end
  end
end

#new_tracking_eventsObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jani/from_json/builder.rb', line 53

def new_tracking_events
  return [] unless hashed_data["tracking_events"]
  hashed_data["tracking_events"].map do |strip_data|
    Jani::FromJson::TrackingEvent.new.tap do |t|
      t.label = strip_data["label"]
      t.url = strip_data["url"]
      t.track_on = strip_data["track_on"]
      t.request_type = strip_data["request_type"]
    end
  end
end