Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
978b40e
commit 2ac3308
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -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" |
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,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 |