citeproc 1.0.0.pre3 → 1.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,20 @@
1
1
  module CiteProc
2
-
2
+
3
3
  module Attributes
4
4
  extend Forwardable
5
5
 
6
6
  def self.included(base)
7
7
  base.extend(ClassMethods)
8
8
  end
9
-
9
+
10
10
  def attributes
11
11
  @attributes ||= {}
12
12
  end
13
-
13
+
14
14
  def_delegators :attributes, :length, :empty?, :values_at, :key?, :value?
15
15
 
16
16
  alias size length
17
-
17
+
18
18
  def read_attribute(key)
19
19
  attributes[filter_key(key)]
20
20
  end
@@ -24,20 +24,29 @@ module CiteProc
24
24
  attributes[filter_key(key)] = filter_value(value)
25
25
  end
26
26
  alias []= write_attribute
27
-
27
+
28
+ def attribute?(key)
29
+ value = read_attribute key
30
+
31
+ return false if value.nil?
32
+ return false if value.respond_to?(:empty?) && value.empty?
33
+
34
+ value.to_s !~ /^(false|no|never)$/i
35
+ end
36
+
28
37
  def filter_key(key)
29
38
  key.to_sym
30
39
  end
31
-
40
+
32
41
  def filter_value(value, key = nil)
33
42
  value.respond_to?(:deep_copy) ? value.deep_copy : value.dup
34
43
  rescue
35
44
  value
36
45
  end
37
-
46
+
38
47
  def merge(other)
39
48
  return self if other.nil?
40
-
49
+
41
50
  case
42
51
  when other.is_a?(String) && /^\s*\{/ =~ other
43
52
  other = MultiJson.decode(other, :symbolize_keys => true)
@@ -55,9 +64,8 @@ module CiteProc
55
64
 
56
65
  self
57
66
  end
58
-
59
67
  alias update merge
60
-
68
+
61
69
  def reverse_merge(other)
62
70
  fail "not implemented yet"
63
71
  end
@@ -72,7 +80,7 @@ module CiteProc
72
80
  [k.to_s, v.respond_to?(:to_citeproc) ? v.to_citeproc : v.to_s]
73
81
  }]
74
82
  end
75
-
83
+
76
84
  # @return [String] a JSON string representation of the attributes
77
85
  def to_json
78
86
  MultiJson.encode(to_citeproc)
@@ -80,14 +88,14 @@ module CiteProc
80
88
 
81
89
  # Don't expose internals to public API
82
90
  private :filter_key, :filter_value
83
-
91
+
84
92
  # initialize_copy should be able to access attributes
85
93
  protected :attributes
86
94
 
87
95
 
88
96
  # Two Attribute-based objects are equal if they are the same object,
89
97
  # or if all their attributes are equal using _#eql?_.
90
- #
98
+ #
91
99
  # @param other [Object] the other object
92
100
  # @return [Boolean] whether or not self and passed-in object are equal
93
101
  def eql?(other)
@@ -100,7 +108,7 @@ module CiteProc
100
108
  other.attributes.each_pair do |key, value|
101
109
  return false unless attributes[key].eql?(value)
102
110
  end
103
-
111
+
104
112
  true
105
113
  end
106
114
  end
@@ -111,10 +119,10 @@ module CiteProc
111
119
  attributes.each do |attribute|
112
120
  digest ^= attribute.hash
113
121
  end
114
-
122
+
115
123
  digest
116
124
  end
117
-
125
+
118
126
  module ClassMethods
119
127
 
120
128
  def create(parameters)
@@ -139,18 +147,18 @@ module CiteProc
139
147
  attr_field(*(field.is_a?(Hash) ? field.to_a.flatten : [field]).map(&:to_s))
140
148
  end
141
149
  end
142
-
150
+
143
151
  def attr_field(field, default = nil, predicate = false)
144
152
  method_id = field.to_s.downcase.gsub(/[-\s]+/, '_')
145
153
 
146
154
  unless instance_methods.include?(method_id)
147
155
  if default
148
156
  define_method(method_id) do
149
- attributes[field.to_sym]
157
+ read_attribute field
150
158
  end
151
159
  else
152
160
  define_method(method_id) do
153
- attributes[field.to_sym] ||= default
161
+ attributes[filter_key(field)] ||= default
154
162
  end
155
163
  end
156
164
  end
@@ -158,23 +166,22 @@ module CiteProc
158
166
  writer_id = [method_id,'='].join
159
167
  unless instance_methods.include?(writer_id)
160
168
  define_method(writer_id) do |value|
161
- attributes[field.to_sym] = value
169
+ write_attribute field, value
162
170
  end
163
171
  end
164
-
165
- predicate_id = [method_id, '?'].join
172
+
173
+ predicate_id = [method_id, '?'].join
166
174
  if predicate && !instance_methods.include?(predicate_id)
167
175
  define_method(predicate_id) do
168
- v = attributes[field.to_sym]
169
- !(!v || (v.respond_to?(:empty?) && v.empty?) || v.to_s =~ /^(false|no|never)$/i)
176
+ attribute?(field)
170
177
  end
171
-
178
+
172
179
  has_predicate = ['has_', predicate_id].join
173
180
  alias_method(has_predicate, predicate_id) unless instance_methods.include?(has_predicate)
174
181
  end
175
182
  end
176
-
183
+
177
184
  end
178
-
185
+
179
186
  end
180
187
  end
@@ -1,3 +1,3 @@
1
1
  module CiteProc
2
- VERSION = '1.0.0.pre3'.freeze
2
+ VERSION = '1.0.0.pre4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citeproc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre3
4
+ version: 1.0.0.pre4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70301801255840 !ruby/object:Gem::Requirement
16
+ requirement: &70361980494920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70301801255840
24
+ version_requirements: *70361980494920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: namae
27
- requirement: &70301801255240 !ruby/object:Gem::Requirement
27
+ requirement: &70361980494120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70301801255240
35
+ version_requirements: *70361980494120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &70301801254680 !ruby/object:Gem::Requirement
38
+ requirement: &70361980493400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.2'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70301801254680
46
+ version_requirements: *70361980493400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70301801253540 !ruby/object:Gem::Requirement
49
+ requirement: &70361980492640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.7'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70301801253540
57
+ version_requirements: *70361980492640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70301801252220 !ruby/object:Gem::Requirement
60
+ requirement: &70361980491960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0.9'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70301801252220
68
+ version_requirements: *70361980491960
69
69
  description: ! "\n A cite processor interface for Citation Style Language (CSL)
70
70
  styles.\n "
71
71
  email:
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: -2750459137594679064
139
+ hash: 4082694825318740316
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements: