Permalink
Browse files

Various fixes and refactorings.

  • Loading branch information...
1 parent c6f71f8 commit a0d9c43eb0f5c12a904367ad914ac43dd060456e @infovore committed Apr 1, 2012
Showing with 15 additions and 4 deletions.
  1. +14 −3 {lib → app/models}/chunk.rb
  2. 0 {lib → app/models}/clipping_processor.rb
  3. +1 −1 app/models/note.rb
@@ -15,13 +15,21 @@ def initialize(chunk_string)
def method_missing(m, *args, &block)
# keeps all the details on the details objects, but delegates up.
- if @details.has_key?(m.to_sym)
+ if @details && @details.has_key?(m.to_sym)
@details[m.to_sym]
else
super
end
end
+ def is_note
+ @details && details[:is_note]
+ end
+
+ def is_highlight
+ @details && details[:is_highlight]
+ end
+
def self.new_from_raw(raw_chunks)
raw_chunks.map {|c| Chunk.new(c)}
end
@@ -71,9 +79,10 @@ def parse_details(details)
end
def parse_detail(detail)
- if detail[:page].match("Note") || detail[:location].match("Note")
+ puts self.inspect
+ if (detail[:page] && detail[:page].match("Note")) || detail[:location].match("Note")
parse_note(detail)
- elsif detail[:page].match("Highlight") || detail[:location].match("Highlight")
+ elsif (detail[:page] && detail[:page].match("Highlight")) || detail[:location].match("Highlight")
parse_highlight(detail)
end
end
@@ -87,6 +96,7 @@ def parse_note(detail)
end
{:is_note => true,
+ :is_highlight => false,
:page => page,
:location => location,
:clipped_at => datetime_from_string(detail[:datetime])}
@@ -108,6 +118,7 @@ def parse_highlight(detail)
:start_loc => start_loc,
:end_loc => end_loc,
:is_highlight => true,
+ :is_note => false,
:clipped_at => datetime_from_string(detail[:datetime])}
end
end
File renamed without changes.
View
@@ -12,7 +12,7 @@ def self.create_from_chunk_for_import(chunk, import)
book_obj = Book.find_or_create_by_title_and_author_id(chunk.title, author_obj.id)
self.create(:content => chunk.content,
:location => chunk.location,
- :page => chunk.page
+ :page => chunk.page,
:author_id => author_obj.id,
:book => book_obj,
:import => import,

0 comments on commit a0d9c43

Please sign in to comment.