Sha256: 9c57f56cdd8b7c43855539eb62da7ad2524ca2c80f14693e1d825800bf7b7ab0

Contents?: true

Size: 644 Bytes

Versions: 2

Compression:

Stored size: 644 Bytes

Contents

require "chh_moretext/version"
require "json"
require "open-uri"

module ChhMoretext
  class Base
    class << self
      def fetch_moretext(number, limit)
        number = "n=#{number}"
        limit  = parse(limit)
        condition = limit.nil? ? "?#{number}" : "?#{number}&#{limit}"
        return JSON(open("http://more.handlino.com/sentences.json#{condition}").read)["sentences"]
      end
    end

    private
      def self.parse(type)
        case type
        when Range   then "limit=#{type.min},#{type.max}"
        when Integer then "limit=#{type}"
        else nil
        end
      end
  end
end

require "chh_moretext/moretext"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chh_moretext-0.1.3 lib/chh_moretext.rb
chh_moretext-0.1.2 lib/chh_moretext.rb