-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add access to calendar data to the MPXJ gem (#770)
- Loading branch information
Showing
22 changed files
with
712 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
module MPXJ | ||
# Represents a calendar | ||
class Calendar < Container | ||
attr_reader :days | ||
attr_reader :weeks | ||
attr_reader :exceptions | ||
|
||
def initialize(parent_project, attribute_values) | ||
super(parent_project, attribute_values.slice('unique_id', 'guid', 'parent_unique_id', 'name', 'type', 'personal', 'minutes_per_day', 'minutes_per_week', 'minutes_per_month', 'minutes_per_year')) | ||
process_days(attribute_values) | ||
process_weeks(attribute_values) | ||
process_exceptions(attribute_values) | ||
end | ||
|
||
# Retrieve the calendar unique ID | ||
# | ||
# @return [Integer] the calendar unique ID | ||
def unique_id | ||
get_integer_value(attribute_values['unique_id']) | ||
end | ||
|
||
# Retrieve the calendar GUID | ||
# | ||
# @return [String] the calendar GUID | ||
def guid | ||
attribute_values['guid'] | ||
end | ||
|
||
# Retrieve the parent calendar unique ID | ||
# | ||
# @return [Integer] the parent calendar unique ID | ||
# @return [nil] if the calendar does not have a parent | ||
def parent_unique_id | ||
get_nillable_integer_value(attribute_values['parent_unique_id']) | ||
end | ||
|
||
# Retrieve the parent calendar of this calendar | ||
# | ||
# @return [Calendar] if this calendar is the child of another calendar | ||
# @return [nil] if this is a base calendar | ||
def parent_calendar | ||
parent_project.get_calendar_by_unique_id(attribute_values['parent_unique_id']&.to_i) | ||
end | ||
|
||
# Retrieve the calendar name | ||
# | ||
# @return [String] the calendar name | ||
def name | ||
attribute_values['name'] | ||
end | ||
|
||
# Retrieve the calendar type | ||
# | ||
# @return [String] the calendar type | ||
def type | ||
attribute_values['type'] | ||
end | ||
|
||
# Retrieve the personal flag | ||
# | ||
# @return [Boolean] true if this is a personal calendar | ||
def personal | ||
get_boolean_value(attribute_values['personal']) | ||
end | ||
|
||
# Retrieve the number of minutes per day | ||
# | ||
# @return [Integer] the number of minutes per day | ||
# @return [nil] if this calendar does not provide a value for minutes per day | ||
def minutes_per_day | ||
get_nillable_integer_value(attribute_values['minutes_per_day']) | ||
end | ||
|
||
# Retrieve the number of minutes per week | ||
# | ||
# @return [Integer] the number of minutes per week | ||
# @return [nil] if this calendar does not provide a value for minutes per week | ||
def minutes_per_week | ||
get_nillable_integer_value(attribute_values['minutes_per_week']) | ||
end | ||
|
||
# Retrieve the number of minutes per month | ||
# | ||
# @return [Integer] the number of minutes per month | ||
# @return [nil] if this calendar does not provide a value for minutes per month | ||
def minutes_per_month | ||
get_nillable_integer_value(attribute_values['minutes_per_month']) | ||
end | ||
|
||
# Retrieve the number of minutes per year | ||
# | ||
# @return [Integer] the number of minutes per year | ||
# @return [nil] if this calendar does not provide a value for minutes per year | ||
def minutes_per_year | ||
get_nillable_integer_value(attribute_values['minutes_per_year']) | ||
end | ||
|
||
private | ||
|
||
def process_days(attribute_values) | ||
@days = attribute_values.slice('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday').map {|name, day| [name, CalendarDay.new(parent_project, day)]}.to_h | ||
end | ||
|
||
def process_weeks(attribute_values) | ||
@weeks = (attribute_values['working_weeks'] || []).map {|week| CalendarWeek.new(parent_project, week)} | ||
end | ||
|
||
def process_exceptions(attribute_values) | ||
@exceptions = (attribute_values['exceptions'] || []).map {|exception| CalendarException.new(parent_project, exception)} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module MPXJ | ||
# Represents a calendar day | ||
class CalendarDay < Container | ||
attr_reader :hours | ||
|
||
def initialize(parent_project, attribute_values) | ||
super(parent_project, attribute_values.slice('type')) | ||
process_hours(attribute_values) | ||
end | ||
|
||
# Retrieve the day type | ||
# | ||
# @return [String] the calendar day type | ||
def type | ||
attribute_values['type'] | ||
end | ||
|
||
private | ||
|
||
def process_hours(attribute_values) | ||
@hours = (attribute_values['hours'] || {}).map do |hours| | ||
CalendarHours.new(parent_project, hours) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module MPXJ | ||
# Represents a calendar exception | ||
class CalendarException < Container | ||
attr_reader :hours | ||
|
||
def initialize(parent_project, attribute_values) | ||
super(parent_project, attribute_values.slice('name', 'from', 'to', 'type')) | ||
process_hours(attribute_values) | ||
end | ||
|
||
# Retrieve the exception name | ||
# | ||
# @return [String] the exception name | ||
def name | ||
attribute_values['name'] | ||
end | ||
|
||
# Retrieve the date on which this exception starts | ||
# | ||
# @return [Time] the exception from date | ||
def from | ||
get_date_value(attribute_values['from']) | ||
end | ||
|
||
# Retrieve the date on which this exception ends | ||
# | ||
# @return [Time] the exception to date | ||
def to | ||
get_date_value(attribute_values['to']) | ||
end | ||
|
||
# Retrieve the exception type | ||
# | ||
# @return [String] the exception type | ||
def type | ||
attribute_values['type'] | ||
end | ||
|
||
private | ||
|
||
def process_hours(attribute_values) | ||
@hours = (attribute_values['hours'] || {}).map do |hours| | ||
CalendarHours.new(parent_project, hours) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module MPXJ | ||
# Represents a range of hours | ||
class CalendarHours < Container | ||
|
||
# Retrieve the the start hour | ||
# | ||
# @return [Time] start hour | ||
def from | ||
get_date_value(attribute_values['from']) | ||
end | ||
|
||
# Retrieve the the finish hour | ||
# | ||
# @return [Time] finish hour | ||
def to | ||
get_date_value(attribute_values['to']) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module MPXJ | ||
# Represents a working week | ||
class CalendarWeek < Container | ||
attr_reader :days | ||
|
||
def initialize(parent_project, attribute_values) | ||
super(parent_project, attribute_values.slice('name', 'effective_from', 'effective_to')) | ||
process_days(attribute_values) | ||
end | ||
|
||
# Retrieve the exception name | ||
# | ||
# @return [String] the exception name | ||
def name | ||
attribute_values['name'] | ||
end | ||
|
||
# Retrieve the date from which this working week is in effect | ||
# | ||
# @return [Time] effective from date | ||
def effective_from | ||
get_date_value(attribute_values['effective_from']) | ||
end | ||
|
||
# Retrieve the date to which this working week is in effect | ||
# | ||
# @return [Time] effective to date | ||
def effective_to | ||
get_date_value(attribute_values['effective_to']) | ||
end | ||
|
||
private | ||
|
||
def process_days(attribute_values) | ||
@days = attribute_values.slice('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday').map {|name, day| [name, CalendarDay.new(parent_project, day)]}.to_h | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.