lib/inat/data/sets/wrappers.rb in inat-get-0.8.0.12 vs lib/inat/data/sets/wrappers.rb in inat-get-0.8.0.13

- old
+ new

@@ -1,11 +1,15 @@ # frozen_string_literal: true require 'date' -class Calendarian +module INat::Report; end +# TODO: переделать в модуль namespace и Base-класс отдельно + +class INat::Report::Period + class << self private :new def [] src @@ -43,120 +47,120 @@ def <=> other return nil unless self.class === other @value <=> other.value end -end + class Year < INat::Report::Period -class Year < Calendarian + class << self - class << self + protected def date_to_value date + date.year + end - protected def date_to_value date - date.year end - end + alias :year :value - alias :year :value + def - num + self.class[@value - num] + end - def - num - self.class[@value - num] - end + def to_s + "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ @value } год" + end - def to_s - "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ @value } год" - end + def query_params + "year=#{ @value }" + end - def query_params - "year=#{ @value }" end -end + class Month < INat::Report::Period -class Month < Calendarian + class << self - class << self + protected def date_to_value date + date.month + end - protected def date_to_value date - date.month end - end + alias :month :value - alias :month :value + NAMES = { + 1 => 'Январь', + 2 => 'Февраль', + 3 => 'Март', + 4 => 'Апрель', + 5 => 'Май', + 6 => 'Июнь', + 7 => 'Июль', + 8 => 'Август', + 9 => 'Сентябрь', + 10 => 'Октябрь', + 11 => 'Ноябрь', + 12 => 'Декабрь' + } - NAMES = { - 1 => 'Январь', - 2 => 'Февраль', - 3 => 'Март', - 4 => 'Апрель', - 5 => 'Май', - 6 => 'Июнь', - 7 => 'Июль', - 8 => 'Август', - 9 => 'Сентябрь', - 10 => 'Октябрь', - 11 => 'Ноябрь', - 12 => 'Декабрь' - } + def to_s + "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ NAMES[@value] }" + end - def to_s - "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ NAMES[@value] }" - end + def query_params + "month=#{ @value }" + end - def query_params - "month=#{ @value }" end -end + class Day < INat::Report::Period -class Day < Calendarian + class << self - class << self + protected def date_to_value date + date.day + end - protected def date_to_value date - date.day end - end + alias :day :value - alias :day :value + def to_s + "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ @value }" + end - def to_s - "<i class=\"glyphicon glyphicon-calendar\"></i>  #{ @value }" - end + def query_params + "day=#{ @value }" + end - def query_params - "day=#{ @value }" end -end + class Winter < INat::Report::Period -class Winter < Calendarian + class << self - class << self - - protected def date_to_value date - month = date.month - if month <= 4 - date.year - elsif month >= 10 - date.year + 1 - else - nil + protected def date_to_value date + month = date.month + if month <= 4 + date.year + elsif month >= 10 + date.year + 1 + else + nil + end end + end - end + alias :winter :value - alias :winter :value + def to_s + "<i class=\"glyphicon glyphicon-calendar\"></i>  Зима #{ @value - 1 }–#{ @value }" + end - def to_s - "<i class=\"glyphicon glyphicon-calendar\"></i>  Зима #{ @value - 1 }–#{ @value }" - end + def query_params + "d1=#{ @value - 1 }-10-01&d2=#{ @value }-04-30" + end - def query_params - "d1=#{ @value - 1 }-10-01&d2=#{ @value }-04-30" end end