lib/csl/style/date.rb in csl-1.0.0.pre16 vs lib/csl/style/date.rb in csl-1.0.0.pre17

- old
+ new

@@ -1,10 +1,9 @@ module CSL class Style class Date < Node - attr_defaults :'date-parts' => 'year-month-day' attr_struct :name, :form, :'range-delimiter', :'date-parts', :variable, *Schema.attr(:display, :formatting, :delimiter) @@ -20,10 +19,16 @@ children[:'date-part'] = [] yield self if block_given? end + # @return [Array<String>] the localized date parts to be used + def date_parts_filter + attributes[:'date-parts'].to_s.split(/-/) + end + alias parts_filter date_parts_filter + def delimiter attributes.fetch(:delimiter, '') end def has_variable? @@ -35,59 +40,40 @@ end def has_form? attribute?(:form) end + alias localized? has_form? def form attributes[:form] end + def numeric? + attributes[:form].to_s =~ /^numeric$/i + end + + def text? + attributes[:form].to_s =~ /^text$/i + end + def has_date_parts? !date_parts.empty? end alias has_parts? has_date_parts? + def has_overrides? + localized? && has_parts? + end end class DatePart < Node + has_no_children + attr_struct :name, :form, :'range-delimiter', *Schema.attr(:formatting, :periods) - def range_delimiter - attributes.fetch(:'range-delimiter', '') - end - - def name - attributes[:name].to_s - end - - def has_form? - attribute?(:form) - end - - def form - case - when has_form? - attributes[:form] - when has_parent? - parent.form - else - nil - end - end - - def year? - name =~ /year/i - end - - def month? - name =~ /month/i - end - - def day? - name =~ /day/i - end + include CSL::DatePart end end end \ No newline at end of file