csl 1.0.0.pre20 → 1.0.0.pre21

Sign up to get free protection for your applications and to get access to all the features.
data/lib/csl/schema.rb CHANGED
@@ -82,6 +82,10 @@ module CSL
82
82
  },
83
83
  :names => %w{
84
84
  names-delimiter
85
+ },
86
+ :conditionals => %w{
87
+ disambiguate is-numeric is-uncertain-date locator
88
+ position type variable
85
89
  }
86
90
  })
87
91
 
@@ -1,16 +1,37 @@
1
1
  module CSL
2
2
  class Style
3
-
3
+
4
4
  class Choose < Node
5
5
 
6
6
  class Block < Node
7
-
8
- def self.matches?(nodename)
9
- nodename.to_s =~ /^if(-else)?|else$/
7
+ attr_struct :match, *Schema.attr(:conditionals)
8
+
9
+ attr_defaults :match => 'all'
10
+
11
+ class << self
12
+ def matches?(nodename)
13
+ nodename.to_s =~ /^if(-else)?|else$/
14
+ end
10
15
  end
11
16
 
17
+ def conditions
18
+ attributes_for(*Schema.attr(:conditionals)).map { |type, values|
19
+ values.to_s.split(/\s+/).map { |value| [type, value] }
20
+ }.flatten(1)
21
+ end
22
+
23
+ def matcher
24
+ case attributes[:match]
25
+ when 'any'
26
+ :any?
27
+ when 'none'
28
+ :none?
29
+ else
30
+ :all?
31
+ end
32
+ end
12
33
  end
13
34
  end
14
-
35
+
15
36
  end
16
37
  end
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.0.0.pre20'.freeze
2
+ VERSION = '1.0.0.pre21'.freeze
3
3
  end
@@ -1,7 +1,50 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module CSL
4
- describe Style::Choose do
4
+ class Style
5
+
6
+ describe Choose do
7
+
8
+ end
9
+
10
+ describe Choose::Block do
11
+
12
+ describe '#conditions' do
13
+ it 'returns an empty list by default' do
14
+ Choose::Block.new.conditions.should be_empty
15
+ end
16
+
17
+ describe 'when the node has a single condition' do
18
+ let(:node) { Choose::Block.new(:'is-numeric' => 'edition' )}
19
+
20
+ it 'returns an array with an array containing the type and value of the condition' do
21
+ node.conditions.should == [[:'is-numeric', 'edition']]
22
+ end
23
+
24
+ describe 'when the node has two conditions' do
25
+ before(:each) { node[:disambiguate] = 'true' }
26
+
27
+ it 'returns an array with two elements' do
28
+ node.conditions.should have_exactly(2).items
29
+ end
30
+
31
+ it 'returns both conditions as arrays' do
32
+ node.conditions.map(&:first).sort.should == [:disambiguate, :'is-numeric']
33
+ node.conditions.map(&:last).sort.should == ['edition', 'true']
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'when the node has a single condition with multiple values' do
39
+ let(:node) { Choose::Block.new(:variable => 'author editor' )}
40
+
41
+ it 'expands the conditions in the result' do
42
+ node.conditions.should == [[:variable, 'author'], [:variable, 'editor']]
43
+ end
44
+ end
45
+ end
46
+
47
+ end
5
48
 
6
49
  end
7
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre20
4
+ version: 1.0.0.pre21
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: namae
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  segments:
185
185
  - 0
186
- hash: -883385539411668909
186
+ hash: -1739872005928970958
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  none: false
189
189
  requirements: