Skip to content

Commit

Permalink
Merge pull request #14 from andyw8/andyw8/add-repeat
Browse files Browse the repository at this point in the history
Add support for `repetition-method` and `repetition-rule`
  • Loading branch information
jyruzicka committed Feb 11, 2024
2 parents a8d01b8 + a04e882 commit abcbfc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
22 changes: 14 additions & 8 deletions lib/rubyfocus/items/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.matches_node?(node)
# * modified
# * document

attr_accessor :note, :flagged, :order, :start, :due, :completed
attr_accessor :note, :flagged, :order, :start, :due, :completed, :repeat, :repetition_method, :repetition_rule
idref :context

def initialize(document, n=nil)
Expand All @@ -31,13 +31,19 @@ def apply_xml(n)

conditional_set(:container_id, (t && t["idref"]) || (f && f["idref"])){ |e| e }

conditional_set(:context_id, n.at_xpath("xmlns:context")) { |e| e["idref"] }
conditional_set(:note, n.at_xpath("xmlns:note")) { |e| e.inner_html.strip }
conditional_set(:order, n.at_xpath("xmlns:order")) { |e| e.inner_html.to_sym }
conditional_set(:flagged, n.at_xpath("xmlns:flagged")) { |e| e.inner_html == "true" }
conditional_set(:start, n.at_xpath("xmlns:start")) { |e| Time.safely_parse(e.inner_html) }
conditional_set(:due, n.at_xpath("xmlns:due")) { |e| Time.safely_parse(e.inner_html) }
conditional_set(:completed, n.at_xpath("xmlns:completed")){ |e| Time.safely_parse(e.inner_html) }
conditional_set(:context_id, n.at_xpath("xmlns:context")) { |e| e["idref"] }
conditional_set(:note, n.at_xpath("xmlns:note")) { |e| e.inner_html.strip }
conditional_set(:order, n.at_xpath("xmlns:order")) { |e| e.inner_html.to_sym }
conditional_set(:flagged, n.at_xpath("xmlns:flagged")) { |e| e.inner_html == "true" }
conditional_set(:start, n.at_xpath("xmlns:start")) { |e| Time.safely_parse(e.inner_html) }
conditional_set(:due, n.at_xpath("xmlns:due")) { |e| Time.safely_parse(e.inner_html) }
conditional_set(:completed, n.at_xpath("xmlns:completed")) { |e| Time.safely_parse(e.inner_html) }
conditional_set(:repeat, n.at_xpath("xmlns:repeat")) { |e| e.inner_html }

# an ICS repeat rule (see RFC2445), e.g. FREQ=WEEKLY;INTERVAL=1
conditional_set(:repetition_rule, n.at_xpath("xmlns:repetition-rule")) { |e| e.inner_html }
# the repeat method: fixed, start-after-completion, or due-after-completion
conditional_set(:repetition_method, n.at_xpath("xmlns:repetition-method")) { |e| e.inner_html }
end

# Convenience methods
Expand Down
6 changes: 6 additions & 0 deletions spec/items/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
expect(@task.due).to eq(Time.utc(2014,02,01,0,0,0))
end

it "should extract repetition data" do
task = Rubyfocus::Task.new(nil, xml(file: "task-repeat"))
expect(task.repetition_rule).to eq("FREQ=YEARLY")
expect(task.repetition_method).to eq("fixed")
end

it "should not choke on empty string values" do
t = Rubyfocus::Task.new(nil, xml(file: "task-nostart"))
expect(t.start).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/xml/task-repeat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<repeat>@1y</repeat>
<repetition-rule>FREQ=YEARLY</repetition-rule>
<repetition-method>fixed</repetition-method>
</task>
</task>

0 comments on commit abcbfc6

Please sign in to comment.