Skip to content

Commit

Permalink
Add the date fields in Entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 24, 2018
1 parent 7f5d985 commit b78ef96
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/cff/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Entity < ModelPart
'city',
'country',
'email',
'date-end',
'date-start',
'fax',
'location',
'name',
Expand All @@ -48,5 +50,31 @@ def initialize(param)
end
end

# :call-seq:
# date_end = date
#
# Set the `date-end` field. If a non-Date object is passed in it will
# be parsed into a Date.
def date_end=(date)
unless Date === date
date = Date.parse(date)
end

@fields['date-end'] = date
end

# :call-seq:
# date_start = date
#
# Set the `date-start` field. If a non-Date object is passed in it will
# be parsed into a Date.
def date_start=(date)
unless Date === date
date = Date.parse(date)
end

@fields['date-start'] = date
end

end
end
14 changes: 14 additions & 0 deletions test/cff_entity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def test_simple_fields_set_and_output_correctly
end
end

def test_date_fields_set_and_output_correctly
date = Date.today
@entity.date_end = date
@entity.date_start = date

assert_equal @entity.date_end, date
assert_equal @entity.date_start, date

y = @entity.fields.to_yaml

assert y.include? "date-end: #{date.to_s}\n"
assert y.include? "date-start: #{date.to_s}\n"
end

def test_tel_fax_fields_set_and_output_correctly
number = "+44 (0) 161-234-5678"
@entity.fax = number
Expand Down

0 comments on commit b78ef96

Please sign in to comment.