Method: CiteProc::Selector#initialize

Defined in:
lib/citeproc/selector.rb

#initialize(attributes = nil) ⇒ Selector

Returns a new instance of Selector.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/citeproc/selector.rb', line 22

def initialize(attributes = nil)
  @conditions, @skip_conditions = {}, {}

  if block_given?
    @type = :ruby

  else
    unless attributes.nil? || attributes.empty?
      attributes.symbolize_keys.each_pair do |key, conditions|
        conditions = convert_conditions(conditions) if conditions.is_a?(Array)

        case key
        when :all, :any, :none
          @type = key
          @conditions.merge!(conditions)

        when :select, :include, :exclude
          @type = Selector.cp2rb[key.to_s]
          @conditions.merge!(conditions)

        when :skip, :quash
          @skip_conditions.merge!(conditions)

        else
          raise TypeError, "failed to create selector from #{key.inspect}"
        end
      end
    end
  end
end