Skip to content

Instantly share code, notes, and snippets.

@atmos
Created July 24, 2008 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atmos/2320 to your computer and use it in GitHub Desktop.
Save atmos/2320 to your computer and use it in GitHub Desktop.
class Note
include ::DataMapper::Resource
property :id, Integer, :serial => true
property :content, String, :length => 2048
property :type, Discriminator
validates_length :content, :minimum => 4, :maximum => 2048
before :save do
self.content = columnize(content)
end
def columnize buf, opts = {}
width = 80
indent = "#{ indent }"
column = []
words = buf.split %r/\s+/o
row = "#{ indent }"
while((word = words.shift))
if((row.size + word.size) < (width - 1))
row << word
else
column << row
row = "#{ indent }"
row << word
end
row << ' ' unless row.size == (width - 1)
end
column << row unless row.strip.empty?
column.join "\n"
end
end
class SliceNote < Note
validates_present :slice_id
validates_present :content
property :slice_id, Integer
belongs_to :slice
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment