Class: CulturalDates::CulturalInterval
- Inherits:
-
Object
- Object
- CulturalDates::CulturalInterval
- Includes:
- Comparable
- Defined in:
- lib/cultural_dates/cultural_interval.rb
Class Method Summary collapse
Instance Method Summary collapse
- #begin_interval ⇒ Object (also: #beginning_interval, #beginning)
- #botb ⇒ Object
- #bote ⇒ Object
- #definite_interval ⇒ Object
- #earliest ⇒ Object
- #earliest_definite ⇒ Object
- #end_interval ⇒ Object (also: #ending_interval, #ending)
- #eotb ⇒ Object
- #eote ⇒ Object
-
#initialize(val = "", debug = false) ⇒ CulturalInterval
constructor
A new instance of CulturalInterval.
- #latest ⇒ Object
- #latest_definite ⇒ Object
- #possible_interval ⇒ Object
- #to_definite_edtf ⇒ Object
- #to_edtf ⇒ Object
-
#to_s ⇒ String
Generate a textual representation of the timeframe of the period.
Constructor Details
#initialize(val = "", debug = false) ⇒ CulturalInterval
Returns a new instance of CulturalInterval.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cultural_dates/cultural_interval.rb', line 13 def initialize(val="", debug=false) if val begin parse_result = DateStringParser.new.parse_with_debug(val, reporter: Parslet::ErrorReporter::Deepest.new) puts "parse_result: #{parse_result.inspect}" if debug transformed_result = DateTransform.new.apply(parse_result) puts "transformed_result: #{transformed_result.inspect}" if debug if transformed_result @value = transformed_result end rescue Parslet::ParseFailed => e @value = nil end else @value = nil end # puts "@value: #{@value}" end |
Class Method Details
.parse(val, debug = false) ⇒ Object
8 9 10 |
# File 'lib/cultural_dates/cultural_interval.rb', line 8 def parse(val, debug=false) return CulturalInterval.new(val, debug) end |
Instance Method Details
#begin_interval ⇒ Object Also known as: beginning_interval, beginning
73 74 75 76 77 |
# File 'lib/cultural_dates/cultural_interval.rb', line 73 def begin_interval from = earliest || :unknown to = earliest_definite || :unknown EDTF::Interval.new(from, to) end |
#botb ⇒ Object
32 33 34 |
# File 'lib/cultural_dates/cultural_interval.rb', line 32 def botb @botb ||= CulturalDate.edtf @value[:botb] end |
#bote ⇒ Object
36 37 38 |
# File 'lib/cultural_dates/cultural_interval.rb', line 36 def bote @bote ||= CulturalDate.edtf @value[:bote] end |
#definite_interval ⇒ Object
98 99 100 101 102 |
# File 'lib/cultural_dates/cultural_interval.rb', line 98 def definite_interval from = earliest_definite || :unknown to = latest_definite || :unknown EDTF::Interval.new(from, to) end |
#earliest ⇒ Object
49 50 51 52 |
# File 'lib/cultural_dates/cultural_interval.rb', line 49 def earliest return nil if botb.unknown? botb.earliest end |
#earliest_definite ⇒ Object
59 60 61 62 63 64 |
# File 'lib/cultural_dates/cultural_interval.rb', line 59 def earliest_definite return nil if eotb.unknown? && bote.unknown? return latest_definite if eotb.unknown? return eotb.earliest if eotb == bote eotb.latest end |
#end_interval ⇒ Object Also known as: ending_interval, ending
82 83 84 85 86 |
# File 'lib/cultural_dates/cultural_interval.rb', line 82 def end_interval from = latest_definite || :unknown to = latest || :unknown EDTF::Interval.new(from, to) end |
#eotb ⇒ Object
40 41 42 |
# File 'lib/cultural_dates/cultural_interval.rb', line 40 def eotb @eotb ||= CulturalDate.edtf @value[:eotb] end |
#eote ⇒ Object
44 45 46 |
# File 'lib/cultural_dates/cultural_interval.rb', line 44 def eote @eote ||= CulturalDate.edtf @value[:eote] end |
#latest ⇒ Object
54 55 56 57 |
# File 'lib/cultural_dates/cultural_interval.rb', line 54 def latest return nil if eote.unknown? eote.latest end |
#latest_definite ⇒ Object
66 67 68 69 70 71 |
# File 'lib/cultural_dates/cultural_interval.rb', line 66 def latest_definite return nil if bote.unknown? && eotb.unknown? return earliest_definite if bote.unknown? return bote.latest if eotb == bote bote.earliest end |
#possible_interval ⇒ Object
90 91 92 93 94 |
# File 'lib/cultural_dates/cultural_interval.rb', line 90 def possible_interval from = earliest || :unknown to = latest || :unknown EDTF::Interval.new(from, to) end |
#to_definite_edtf ⇒ Object
109 110 111 |
# File 'lib/cultural_dates/cultural_interval.rb', line 109 def to_definite_edtf definite_interval.edtf end |
#to_edtf ⇒ Object
105 106 107 |
# File 'lib/cultural_dates/cultural_interval.rb', line 105 def to_edtf possible_interval.edtf end |
#to_s ⇒ String
Generate a textual representation of the timeframe of the period.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/cultural_dates/cultural_interval.rb', line 115 def to_s # Handle special "throughout" case if (eotb.known? && bote.known?) && !(botb.known? || eote.known?) && eotb == bote return "throughout #{eotb}" end # Handle special "throughout, until" case if (eotb.known? && bote.known? && eote.known?) && !botb.known? && eotb == bote return "throughout #{eotb} until no later than #{eote}" end # Handle special "on" case if (botb.known? && eotb.known? && bote.known? && eote.known?) && (botb == eotb && bote == eote && botb == eote) && botb.earliest == botb.latest return "on #{botb}" end first_string = "" if botb.known? && eotb.known? if botb == eotb first_string = botb else first_string = "sometime between #{botb} and #{eotb}" end elsif botb.known? first_string = "after #{botb}" elsif eotb.known? first_string = "by #{eotb}" end second_string = nil if bote.known? && eote.known? if bote == eote second_string = bote else second_string = "sometime between #{bote} and #{eote}" end elsif bote.known? second_string = "at least #{bote}" elsif eote.known? second_string = "no later than #{eote}" end [first_string,second_string].compact.join(" until ").strip end |