Class: Comic
- Inherits:
-
Object
- Object
- Comic
- Defined in:
- lib/pig-media-server/model/comic.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #files ⇒ Object
- #id ⇒ Object
- #image(count) ⇒ Object
- #info(count) ⇒ Object
-
#initialize(record) ⇒ Comic
constructor
A new instance of Comic.
- #left ⇒ Object
- #max_page ⇒ Object
- #page(count) ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(record) ⇒ Comic
Returns a new instance of Comic.
6 7 8 9 |
# File 'lib/pig-media-server/model/comic.rb', line 6 def initialize record self.record = record self.config = Pit.get "Pig Media Server" end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/pig-media-server/model/comic.rb', line 5 def config @config end |
#record ⇒ Object
Returns the value of attribute record.
5 6 7 |
# File 'lib/pig-media-server/model/comic.rb', line 5 def record @record end |
Instance Method Details
#files ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pig-media-server/model/comic.rb', line 53 def files ar = [] Zip::Archive.open(self.record.path) do |as| as.each do |a| if a.name =~ /.png$/ or a.name =~ /.jpg$/ or a.name =~ /.PNG$/ or a.name =~ /.JPG$/ or a.name =~ /.jpeg$/ or a.name =~ /.JPEG$/ ar << a.name end end end ar.sort end |
#id ⇒ Object
10 |
# File 'lib/pig-media-server/model/comic.rb', line 10 def id; self.record._key;end |
#image(count) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pig-media-server/model/comic.rb', line 37 def image count count = count.to_i-1 count = 0 if count < 0 file = nil name = self.files[count] Zip::Archive.open(self.record.path) do |as| as.each do |a| if a.name == name file = a.read break end end end Magick::Image.from_blob(file).first end |
#info(count) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/pig-media-server/model/comic.rb', line 19 def info count m = self.image(count) x = m.columns y = m.rows {portlait: (x.to_f/y.to_f > 1.0)} end |
#left ⇒ Object
13 14 15 16 17 |
# File 'lib/pig-media-server/model/comic.rb', line 13 def left data = "#{self.config['user_data_path']}/comic_#{self.record._key}.comic" open(data, 'w'){|f| f.puts({left: false}.to_json)} unless File.exist? data JSON.parse(open(data).read)['left'] end |
#max_page ⇒ Object
11 |
# File 'lib/pig-media-server/model/comic.rb', line 11 def max_page; self.files.count; end |
#page(count) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pig-media-server/model/comic.rb', line 26 def page count m = self.image count case m.format when "JPEG" type = 'image/jpeg' when "PNG" type = 'image/png' end [m.to_blob, type] end |
#title ⇒ Object
12 |
# File 'lib/pig-media-server/model/comic.rb', line 12 def title; self.record.path.split("/").last;end |