iptcr 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 801173393ff24fc468de4a0c0842f03f28058b4b
4
- data.tar.gz: fceac79394ba9e6823b39228652e440a69a78415
3
+ metadata.gz: a41336d23d8fbd12a7106d88009508ae869357e7
4
+ data.tar.gz: ad2db1e2b64427ffafed283b9580fefa99524471
5
5
  SHA512:
6
- metadata.gz: 038c87adeebe6b3047abfb4304145b2fca3344ccef31de92ff9ab1f93d68b5ca42a32199280a02bf8689fde9d464de544126a2f6ff384f97515c91b67c704e02
7
- data.tar.gz: 612b8924a4456eb48d252be3f097dd10b75d5acb7d5b6943133691ea927178878eeb41ce72719c734fc9455f36f119c9b0fcceb2c9eeab9195b4e45b969354e8
6
+ metadata.gz: 1c514478623a9dd1c8f475de25ef93fbe03202b4275c09534bfa0c2885ae59b06bd486de529802521410e4855e709e8fc781b17184762f973e027fa3afdde710
7
+ data.tar.gz: d03b0e1117cdd200827a9dfa99a879950c4ea8b2b8562de065657cc098af7d4cc732cdc64c9ce7520ccbd08407bdc232e85d8bf2fcf52ce3244f4e09b3905c92
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,13 +1,15 @@
1
1
  require "iptcr/version"
2
2
 
3
3
  module IPTCR
4
- def self.parse(value, length: nil)
4
+ class Malformed < RuntimeError; end
5
+
6
+ def self.parse(value, length: nil, **kwargs)
5
7
  if value.is_a? String
6
8
  require "stringio"
7
9
  length ||= value.bytesize
8
- IPTC.new(StringIO.new(value), length: length)
10
+ IPTC.new(StringIO.new(value), length: length, **kwargs)
9
11
  else
10
- IPTC.new(value, length: length)
12
+ IPTC.new(value, length: length, **kwargs)
11
13
  end
12
14
  end
13
15
 
@@ -2,8 +2,6 @@ require "iptcr"
2
2
  require "iptcr/records"
3
3
 
4
4
  module IPTCR
5
- class Malformed < RuntimeError; end
6
-
7
5
  # # IPTC
8
6
  #
9
7
  # ## Notes
@@ -24,7 +22,8 @@ module IPTCR
24
22
  # IPTC IIM specifics the default encoding is ISO646/4873, which is roughly ASCII
25
23
  DEFAULT_ENCODING = Encoding::ASCII
26
24
 
27
- def initialize(io, length:)
25
+ def initialize(io, length: nil, default_encoding: nil)
26
+ @encoding = default_encoding
28
27
  @fields = []
29
28
  read_fields(io, length: length)
30
29
  end
@@ -95,8 +94,10 @@ module IPTCR
95
94
  case field.value
96
95
  when "\x1b%G"
97
96
  @encoding = Encoding::UTF_8
97
+ when "\x1b\xe2\x80\xa2A"
98
+ @encoding = Encoding::ISO_8859_1 # Latin 1
98
99
  else
99
- EXIFR.logger.warn { "IPTC: Unknown codec character set: #{field.value.inspect}" }
100
+ warn "IPTC: Unknown encoding: #{field.value.inspect}, using default #{encoding}"
100
101
  end
101
102
  end
102
103
 
@@ -176,10 +177,10 @@ module IPTCR
176
177
  when "string"
177
178
  # Record number 1 is always the default encoding
178
179
  if record_number == 1
179
- @data.force_encoding(DEFAULT_ENCODING)
180
+ @data.force_encoding(DEFAULT_ENCODING) unless @data.nil?
180
181
  # Records 2-6 and 8 respect tagged encoding
181
182
  elsif (2..6).include?(record_number) || record_number == 8
182
- @data.force_encoding(encoding)
183
+ @data.force_encoding(encoding) unless @data.nil?
183
184
  # Other behaviour is undefined
184
185
  else
185
186
  @data
@@ -1,3 +1,3 @@
1
1
  module IPTCR
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -83,6 +83,12 @@ class IPTCTest < Minitest::Test
83
83
  assert_equal("☃".force_encoding("UTF-8"), iptc["ObjectName"])
84
84
  end
85
85
 
86
+ def test_iptc_default_encoding_string
87
+ iptc = IPTCR.parse("\x1c\x02\x05\x00\x01\x80".b, default_encoding: "windows-1252")
88
+ assert_equal(Encoding::Windows_1252, iptc["ObjectName"].encoding)
89
+ assert_equal("€", iptc["ObjectName"].encode("utf-8"))
90
+ end
91
+
86
92
  def test_iptc_string_list
87
93
  iptc = IPTCR.parse("\x1c\x01\x05\x00\x05Hello\x1c\x01\x05\x00\x05World".b)
88
94
  assert_equal(2, iptc.fields.size)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iptcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Cochran
@@ -28,7 +28,7 @@ cert_chain:
28
28
  52G9HuhbVSTgE/I10H9qZBOE3qdP8ka/Fk0PUrux/DuUanNZgSKJokrQvRA4H9Au
29
29
  WpPA7HJYV6msWQiukoBEhfQ2l6Fl2HUwntvX3MCcFNHeJJ5ETERp9alo88E=
30
30
  -----END CERTIFICATE-----
31
- date: 2015-12-18 00:00:00.000000000 Z
31
+ date: 2016-01-05 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
@@ -107,11 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.4.5.1
110
+ rubygems_version: 2.5.1
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Parse IPTC data
114
114
  test_files:
115
115
  - test/iptc_test.rb
116
116
  - test/test_helper.rb
117
- has_rdoc:
metadata.gz.sig CHANGED
Binary file