Class: When::CalendarTypes::Yerm

Inherits:
CyclicTableBased show all
Defined in:
lib/when_exe/region/yerm.rb

Overview

Yerm Lunar Calendar

Constant Summary

Constants included from When::Coordinates

When::Coordinates::Bahai, When::Coordinates::Chinese, When::Coordinates::Common, When::Coordinates::DefaultDateIndices, When::Coordinates::DefaultDayIndex, When::Coordinates::DefaultTimeIndices, When::Coordinates::Indian, When::Coordinates::Iranian, When::Coordinates::Javanese, When::Coordinates::LocationTable, When::Coordinates::MATCH, When::Coordinates::Mayan, When::Coordinates::PERIOD, When::Coordinates::PERIOD_NAME, When::Coordinates::PRECISION, When::Coordinates::PRECISION_NAME, When::Coordinates::Russian, When::Coordinates::Tibetan, When::Coordinates::VALUE, When::Coordinates::Yi

Constants included from Namespace

Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD

Instance Attribute Summary

Attributes inherited from TM::Calendar

#epoch_in_CE, #reference_frame, #time_basis

Attributes inherited from TM::ReferenceSystem

#domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#child, #keys, #locale, #namespace

Class Method Summary collapse

Methods inherited from CyclicTableBased

#_number_to_coordinates

Methods inherited from TableBased

#_coordinates_to_number, #_length, #_number_to_coordinates

Methods inherited from TM::Calendar

#_new_month_, _setup_, #_to_month_number_, #date_trans, #jul_trans, #rate_of_clock, #strftime, #time_standard, #to_cal_date, #to_julian_date, #to_universal_time

Methods included from When::Coordinates

to_deg, to_deg_225, to_dms

Methods inherited from TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _instance, _setup_, _setup_info, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir

Methods included from Parts::Resource::Pool

#[], #[]=, #_setup_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Parts::Resource

Class Method Details

.parse(source, abbr = nil) ⇒ String

Analyze notation with crescent

Parameters:

  • source (String)

    Notation with crescents

  • abbr (Array<Integer>) (defaults to: nil)

    Upper default elements (default - today's Yerm date)

Returns:

  • (String)

    Notation with hyphens

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/when_exe/region/yerm.rb', line 46

def self.parse(source, abbr=nil)
  c, y, m, d = abbr || (When::Yerm^When.today).cal_date
  case source
  when /\A(-?\d+)[-\(](\d+)\((\d+)\((\d+)\z/; c, y, m, d = [$1, $2, $3, $4]
  when /\A(-?\d+)-(\d+)\((\d+)\z/           ; c, y, m, d = [$1, $2, $3    ]
  when /\A(-?\d+)-(\d+)\z/                  ; c, y, m, d = [$1, $2        ]
  when /\A(-?\d+)-\z/                       ; c, y, m, d = [$1            ]
  when /\A(\d+)\((\d+)\((\d+)\z/            ;    y, m, d = [    $1, $2, $3]
  when /\A(\d+)\((\d+)\z/                   ;       m, d = [        $1, $2]
  when /\A(\d+)\z/                          ;          d =              $1

  when /\A(-?\d+)-(\d+)\)(\d+)\)(\d+)\z/    ; c, y, m, d = [$1, $4, $3, $2]

  when /\A(\d+)\)(\d+)\)(\d+)[-\)](-?\d+)\z/; c, y, m, d = [$4, $3, $2, $1]
  when /\A(\d+)\)(\d+)-(-?\d+)\z/           ; c, y, m, d = [$3, $2, $1    ]
  when /\A(\d+)-(-\d+)\z/                   ; c, y, m, d = [$2, $1        ]
  when /\A(-\d+)\z/                         ; c, y, m, d = [$1            ]
  when /\A(\d+)\)(\d+)\)(\d+)\z/            ;    y, m, d = [    $3, $2, $1]
  when /\A(\d+)\)(\d+)\z/                   ;       m, d = [        $2, $1]
  else                                      ; c, y, m, d = [              ]
  end

  ordered = [c, y, m, d]
  ordered.pop until ordered.last || ordered.empty?
  raise ArgumentError, "can't parse #{source}" if ordered.empty? || ordered.include?(nil)
  ordered.map {|n| n.to_s}.join('-')
end