Module: When::CalendarTypes::Lunar
- Included in:
- EphemerisBasedLunar, EphemerisBasedLuniSolar, Jewish, PatternTableBasedLuniSolar, ThaiP, ThaiT
- Defined in:
- lib/when_exe/calendartypes.rb
Overview
太陰(太陽)暦の朔閏パターンを扱うモジュール
Constant Summary collapse
- Pattern =
' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Instance Method Summary collapse
- #_verify(source, target) ⇒ Object
-
#lunar_table(year_range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を生成する.
-
#verify(base, year_range = base.year_range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を比較する.
Instance Method Details
#_verify(source, target) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/when_exe/calendartypes.rb', line 229 def _verify(source, target) return nil if source == target return {source => target} unless source.length == target.length indices = [] index = [] source.length.times do |i| if source[i..i] == target[i..i] unless index.empty? indices << index index = [] end else index << i end end indices << index unless index.empty? ranges = [] indices.each do |index| if ranges.empty? || index.first > ranges.last.last + 2 ranges << index else ranges[-1] = [ranges.last.first,index.last] end end hash = {} ranges.each do |index| range = index.first..index.last hash[source[range]] = target[range] end test = source.dup hash.each_pair do |key, value| test.sub!(key, value) end # raise ArgumentError, "can't replace '#{source}'=>'#{target}' by #{hash}." unless test == target return hash if test == target {source => target} end |
#lunar_table(year_range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を生成する
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/when_exe/calendartypes.rb', line 182 def lunar_table(year_range, length=30, duration=When::P1M) date = When.TemporalPosition(year_range.first, {:frame=>self}).floor table = [] hash = { 'origin_of_MSC' => year_range.first, 'origin_of_LSC' => date.to_i, 'rule_table' => table } list = '' while year_range.include?(date[When::YEAR]) month = date[When::MONTH] * 1 char = Pattern[month..month] char = char.downcase unless date.length(When::MONTH) == length list += char succ = date + duration unless date[When::YEAR] == succ[When::YEAR] table << list list = '' end date = succ end hash end |
#verify(base, year_range = base.year_range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を比較する
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/when_exe/calendartypes.rb', line 215 def verify(base, year_range=base.year_range, length=30, duration=When::P1M) year_range = When::Parts::GeometricComplex.new(year_range) & When::Parts::GeometricComplex.new(self.year_range) if respond_to?(:year_range) base_table = base.lunar_table(year_range, length, duration) self_table = self.lunar_table(year_range, length, duration) hash = {} year_range.each do |year| difference = _verify(base_table['rule_table'][year-year_range.first], self_table['rule_table'][year-year_range.first]) hash[year] = difference if difference end hash end |