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(range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を生成する.
-
#verify(base, range = base.range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を比較する.
Instance Method Details
#_verify(source, target) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 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 |
# File 'lib/when_exe/calendartypes.rb', line 218 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(range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を生成する
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/when_exe/calendartypes.rb', line 171 def lunar_table(range, length=30, duration=When::P1M) date = When.TemporalPosition(range.first, {:frame=>self}).floor table = [] hash = { 'origin_of_MSC' => range.first, 'origin_of_LSC' => date.to_i, 'rule_table' => table } list = '' while range.include?(date[YEAR]) month = date[MONTH] * 1 char = Pattern[month..month] char = char.downcase unless date.length(MONTH) == length list += char succ = date + duration unless date[YEAR] == succ[YEAR] table << list list = '' end date = succ end hash end |
#verify(base, range = base.range, length = 30, duration = When::P1M) ⇒ Hash
朔閏表を比較する
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/when_exe/calendartypes.rb', line 204 def verify(base, range=base.range, length=30, duration=When::P1M) range = When::Parts::GeometricComplex.new(range) & When::Parts::GeometricComplex.new(self.range) if respond_to?(:range) base_table = base.lunar_table(range, length, duration) self_table = self.lunar_table(range, length, duration) hash = {} range.each do |year| difference = _verify(base_table['rule_table'][year-range.first], self_table['rule_table'][year-range.first]) hash[year] = difference if difference end hash end |