Sha256: 6d8ec2f3ab7e453ba1246937e6ed61793d3387c73b84f3e03f20826b34b58781

Contents?: true

Size: 1.67 KB

Versions: 18

Compression:

Stored size: 1.67 KB

Contents

module CSL
  class Style

    class Sort < Node

      #attr_children :key
      #alias_child :sort_keys, :key

      def initialize(attributes = {})
        super(attributes)
        yield self if block_given?
      end

      alias sort_keys children
      alias sort_keys? has_children?
      alias has_sort_keys? has_children?

      class Key < Node

        attr_struct :variable, :macro, :sort,
          :'names-min', :'names-use-first', :'names-use-last'

        attr_defaults :sort => 'ascending'

        has_no_children

        def name_options
          options = {}

          options[:'et-al-min'] = options[:'et-al-subsequent-min'] =
            attributes[:'names-min'] if attribute? :'names-min'

          options[:'et-al-use-first'] = options[:'et-al-subsequent-use-first'] =
            attributes[:'names-use-first'] if attribute? :'names-use-first'

          options[:'et-al-use-last'] = options[:'et-al-subsequent-use-last'] =
            attributes[:'names-use-last'] if attribute? :'names-use-last'

          options
        end

        def ascending?
          attributes[:sort] =~ /^ascending$/i
        end

        def ascending!
          attributes[:sort] = 'ascending'
        end

        def descending?
          !ascending?
        end

        def descending!
          attributes[:sort] = 'descending'
        end

        def macro?
          attribute? :macro
        end

        def macro
          fail 'cannot resolve macro: not associated with style' unless
            !root? && root.respond_to?(:macros)

          root.macros[attributes[:macro].to_s]
        end

        def variable
          attributes[:variable]
        end

      end

    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
csl-2.0.0 lib/csl/style/sort.rb
csl-1.6.0 lib/csl/style/sort.rb
csl-1.5.2 lib/csl/style/sort.rb
csl-1.5.1 lib/csl/style/sort.rb
csl-1.5.0 lib/csl/style/sort.rb
csl-1.4.5 lib/csl/style/sort.rb
csl-1.4.4 lib/csl/style/sort.rb
csl-1.4.3 lib/csl/style/sort.rb
csl-1.4.2 lib/csl/style/sort.rb
csl-1.4.1 lib/csl/style/sort.rb
csl-1.4.0 lib/csl/style/sort.rb
csl-1.3.2 lib/csl/style/sort.rb
csl-1.3.1 lib/csl/style/sort.rb
csl-1.3.0 lib/csl/style/sort.rb
csl-1.2.3 lib/csl/style/sort.rb
csl-1.2.2 lib/csl/style/sort.rb
csl-1.2.1 lib/csl/style/sort.rb
csl-1.2.0 lib/csl/style/sort.rb