asciinema.org/app/models/playback_options.rb

46 lines
1014 B
Ruby
Raw Normal View History

class PlaybackOptions
2015-10-13 18:38:37 +00:00
class Time < Virtus::Attribute
def coerce(value)
value = value.presence
if value
smh = value.strip.sub("m", ":0").split(":").reverse
smh[0].to_i + smh[1].to_i * 60 + smh[2].to_i * 3600
end
end
end
include Virtus.model
attribute :speed, Float, default: 1.0
attribute :size, String, default: 'small'
2015-10-13 18:38:37 +00:00
attribute :autoplay, Boolean
2014-08-09 11:09:54 +00:00
attribute :loop, Boolean, default: false
2016-04-21 13:13:32 +00:00
attribute :preload, Boolean, default: true
attribute :benchmark, Boolean, default: false
attribute :theme, String, default: Theme::DEFAULT
2015-10-13 18:38:37 +00:00
attribute :t, Time
2015-12-22 17:40:20 +00:00
attribute :v0, Boolean, default: false
2016-05-01 17:15:04 +00:00
attribute :poster, String
def as_json(*)
2015-10-13 18:38:37 +00:00
opts = {
speed: speed,
autoPlay: autoplay.nil? ? !!t : autoplay,
loop: loop,
2016-04-21 13:13:32 +00:00
preload: preload,
fontSize: size,
2015-10-13 18:38:37 +00:00
theme: theme,
2016-05-01 17:15:04 +00:00
poster: poster,
}
2015-10-13 18:38:37 +00:00
if t
opts = opts.merge(startAt: t)
end
opts
end
end