Skip to content

Commit

Permalink
finished 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chinghanho committed Jan 4, 2013
1 parent 978b40e commit 2ac3308
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/chh_moretext.rb
@@ -1,5 +1,30 @@
require "chh_moretext/version"
require "json"
require "open-uri"

module ChhMoretext
# Your code goes here...
class Base
class << self
def fetch_moretext(number, limit)
number = "n=#{number}"

if limit.is_a?(Range)
limit = "limit=#{limit.min},#{limit.max}"
elsif limit.is_a?(Integer)
limit = "limit=#{limit}"
else
limit = nil
end

if limit.nil?
condition = "?#{number}"
else
condition = "?#{number}&#{limit}"
end
return JSON(open("http://more.handlino.com/sentences.json#{condition}").read)["sentences"]
end
end
end
end

require "chh_moretext/moretext"
23 changes: 23 additions & 0 deletions lib/chh_moretext/moretext.rb
@@ -0,0 +1,23 @@
module ChhMoretext
class Moretext < Base
class << self
def sentence(sentence_length_range = nil)
fetch_moretext(1, sentence_length_range)
end

def sentences(sentence_count = 1, sentence_length_range = nil)
fetch_moretext(sentence_count, sentence_length_range).join("")
end

def paragraph(sentence_count = 3)
sentences(sentence_count)
end

def paragraphs(paragraph_count = 3)
[].tap { |paragraphs|
paragraph_count.times { paragraphs << paragraph }
}.join("\r\n\r\n")
end
end
end
end

0 comments on commit 2ac3308

Please sign in to comment.