Class: ZPNG::Chunk::ITXT
- Inherits:
-
TextChunk
- Object
- ZPNG::Chunk
- TextChunk
- ZPNG::Chunk::ITXT
- Defined in:
- lib/zpng/text_chunk.rb
Constant Summary
Constants inherited from TextChunk
Constants inherited from ZPNG::Chunk
Instance Attribute Summary collapse
-
#cflag ⇒ Object
compression flag & method.
-
#cmethod ⇒ Object
compression flag & method.
-
#language ⇒ Object
Returns the value of attribute language.
-
#translated_keyword ⇒ Object
Returns the value of attribute translated_keyword.
Attributes inherited from TextChunk
Attributes inherited from ZPNG::Chunk
#crc, #data, #idx, #offset, #size, #type
Instance Method Summary collapse
-
#initialize(*args) ⇒ ITXT
constructor
A new instance of ITXT.
- #to_hash ⇒ Object
Methods inherited from TextChunk
Methods inherited from ZPNG::Chunk
#check, #crc_ok?, #export, #export_data, #fix_crc!, from_stream, #inspect, #valid?
Methods included from DeepCopyable
Constructor Details
#initialize(*args) ⇒ ITXT
Returns a new instance of ITXT.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/zpng/text_chunk.rb', line 57 def initialize *args super # The text, unlike the other strings, is not null-terminated; its length is implied by the chunk length. # http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.iTXt @keyword, @cflag, @cmethod, @language, @translated_keyword, @text = data.unpack('Z*CCZ*Z*a*') if @cflag == 1 && @cmethod == 0 @text = Zlib::Inflate.inflate(@text) end if @text @text.force_encoding('utf-8') rescue nil end if @translated_keyword @translated_keyword.force_encoding('utf-8') rescue nil end end |
Instance Attribute Details
#cflag ⇒ Object
compression flag & method
55 56 57 |
# File 'lib/zpng/text_chunk.rb', line 55 def cflag @cflag end |
#cmethod ⇒ Object
compression flag & method
55 56 57 |
# File 'lib/zpng/text_chunk.rb', line 55 def cmethod @cmethod end |
#language ⇒ Object
Returns the value of attribute language.
56 57 58 |
# File 'lib/zpng/text_chunk.rb', line 56 def language @language end |
#translated_keyword ⇒ Object
Returns the value of attribute translated_keyword.
56 57 58 |
# File 'lib/zpng/text_chunk.rb', line 56 def translated_keyword @translated_keyword end |
Instance Method Details
#to_hash ⇒ Object
73 74 75 76 77 78 |
# File 'lib/zpng/text_chunk.rb', line 73 def to_hash super.tap do |h| h[:language] = @language if @language || !@language.empty? h[:translated_keyword] = @translated_keyword if @translated_keyword || !@translated_keyword.empty? end end |