Class: Stupidedi::Versions::FunctionalGroups::FortyTen::ElementTypes::DateVal::Improper
- Inherits:
-
Stupidedi::Versions::FunctionalGroups::FortyTen::ElementTypes::DateVal
- Object
- Stupidedi::Values::AbstractVal
- Stupidedi::Values::AbstractElementVal
- Stupidedi::Values::SimpleElementVal
- Stupidedi::Versions::FunctionalGroups::FortyTen::ElementTypes::DateVal
- Stupidedi::Versions::FunctionalGroups::FortyTen::ElementTypes::DateVal::Improper
- Defined in:
- lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb
Overview
Date with a partially-specified year (two digits, missing century). Shouldn’t be directly instantiated – instead, use the constuctor method value
Instance Attribute Summary collapse
- #day ⇒ Integer readonly
- #month ⇒ Integer readonly
- #year ⇒ Integer readonly
Attributes inherited from Stupidedi::Values::SimpleElementVal
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#century(cc) ⇒ Proper
Create a proper date using the given century ‘cc`.
- #copy(changes = {}) ⇒ Improper
- #empty? ⇒ Boolean
-
#future ⇒ Proper
Create a proper date which cannot be older than the current date.
-
#initialize(year, month, day, usage, position) ⇒ Improper
constructor
A new instance of Improper.
- #inspect ⇒ String
-
#newest(date) ⇒ Proper
Create a proper date which cannot be newer than the given ‘date` and cannot be older than one year before the given `date`.
-
#oldest(date) ⇒ Proper
Create a proper date which cannot be older than the given ‘date` and cannot be newer than one year after the given `date`.
-
#past ⇒ Proper
Create a proper date which cannot be newer than the current date.
- #proper? ⇒ Boolean
- #to_s ⇒ String
- #valid? ⇒ Boolean
Methods inherited from Stupidedi::Versions::FunctionalGroups::FortyTen::ElementTypes::DateVal
#date?, empty, parse, #too_long?, #too_short?, value
Methods inherited from Stupidedi::Values::SimpleElementVal
#allowed?, #component?, #date?, #definition, #id?, #leaf?, #numeric?, #simple?, #string?, #time?, #to_x12
Methods inherited from Stupidedi::Values::AbstractElementVal
Methods inherited from Stupidedi::Values::AbstractVal
#blank?, #characters, #component?, #composite?, #definition, #element?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?
Methods included from Color
Constructor Details
#initialize(year, month, day, usage, position) ⇒ Improper
Returns a new instance of Improper.
293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 293 def initialize(year, month, day, usage, position) @year, @month, @day = year, month, day # Check that date is reasonably valid unless @year.between?(0, 99) and @month.between?(1, 12) and @day.between?(1, 31) raise Exceptions::InvalidElementError, "invalid date year: #{year}, month: #{month}, day: #{day}" end super(usage, position) end |
Instance Attribute Details
#day ⇒ Integer (readonly)
291 292 293 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 291 def day @day end |
#month ⇒ Integer (readonly)
288 289 290 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 288 def month @month end |
#year ⇒ Integer (readonly)
285 286 287 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 285 def year @year end |
Instance Method Details
#==(other) ⇒ Boolean
Not commutative
438 439 440 441 442 443 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 438 def ==(other) eql?(other) or (@day == other.day and @year == other.year and @month == other.month) end |
#century(cc) ⇒ Proper
Create a proper date using the given century ‘cc`
333 334 335 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 333 def century(cc) Proper.new(100 * cc + @year, @month, @day, usage, position) end |
#copy(changes = {}) ⇒ Improper
306 307 308 309 310 311 312 313 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 306 def copy(changes = {}) Improper.new \ changes.fetch(:year, @year), changes.fetch(:month, @month), changes.fetch(:day, @day), changes.fetch(:usage, usage), changes.fetch(:position, position) end |
#empty? ⇒ Boolean
319 320 321 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 319 def empty? false end |
#future ⇒ Proper
Create a proper date which cannot be older than the current date
410 411 412 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 410 def future oldest(Date.today) end |
#inspect ⇒ String
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 415 def inspect id = definition.bind do |d| "[#{'% 5s' % d.id}: #{d.name}]".bind do |s| if usage.forbidden? ansi.forbidden(s) elsif usage.required? ansi.required(s) else ansi.optional(s) end end end ansi.element("DT.value#{id}") << "(XX#{'%02d-%02d-%02d' % [@year, @month, @day]})" end |
#newest(date) ⇒ Proper
Create a proper date which cannot be newer than the given ‘date` and cannot be older than one year before the given `date`.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 378 def newest(date) cc, yy = date.year.divmod(100) if @year < yy century(cc) elsif @year > yy century(cc - 1) else if @month < date.month century(cc) elsif @month > date.month century(cc - 1) else if @day <= date.day century(cc) else century(cc - 1) end end end end |
#oldest(date) ⇒ Proper
Create a proper date which cannot be older than the given ‘date` and cannot be newer than one year after the given `date`.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 346 def oldest(date) cc, yy = date.year.divmod(100) if @year < yy century(cc + 1) elsif @year > yy century(cc) else if @month < date.month century(cc + 1) elsif @month > date.month century(cc) else if @day < date.day century(cc + 1) else century(cc) end end end end |
#past ⇒ Proper
Create a proper date which cannot be newer than the current date
403 404 405 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 403 def past newest(Date.today) end |
#proper? ⇒ Boolean
323 324 325 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 323 def proper? false end |
#to_s ⇒ String
432 433 434 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 432 def to_s '%04d%02d%02d' % [@year, @month, @day] end |
#valid? ⇒ Boolean
315 316 317 |
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/date_val.rb', line 315 def valid? true end |