Module: When::Coordinates::Temporal::IndexConversion

Defined in:
lib/when_exe/coordinates.rb

Instance Method Summary collapse

Instance Method Details

#_from_index(date) ⇒ When::Coordinates::Pair

indexのPair化

Parameters:

  • date (Array<Numeric>)

    最下位が index になっている日時要素

Returns:



1837
1838
1839
1840
1841
1842
1843
# File 'lib/when_exe/coordinates.rb', line 1837

def _from_index(date)
  return nil unless @pair[date.size-1]
  ids = _ids(date[0..-2])
  m   = ids[date[-1]] if (ids)
  return Pair._force_pair(m) if (ids && m)
  return Pair.new(+date[-1]+@base[date.length-1], 0)
end

#_to_index(date) ⇒ When::Coordinates::Pair

Pairのindex化

Parameters:

  • date (Array<Numeric>)

    最下位が When::Coordinates::Pair になっている日時要素

Returns:



1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
# File 'lib/when_exe/coordinates.rb', line 1852

def _to_index(date)
  return nil unless @pair[date.size-1]
  ids = _ids(date[0..-2])
  i   = ids.index(date[-1]) if ids
  return i if i
  return nil unless ids && date[-1].kind_of?(Pair)
  digit = Pair.new(date[-1].trunk, date[-1].branch)
  while digit.branch > 0
    digit.branch -= 1
    i = ids.index(digit)
    return i + date[-1].branch - digit.branch if i
  end
  return nil
end