Sha256: 9e8eac536e148e6d04a122fa2f761bc81f15f2e6925c4bb8f7431ddf6f41d092

Contents?: true

Size: 690 Bytes

Versions: 2

Compression:

Stored size: 690 Bytes

Contents

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

module ChhMoretext
  class Base
    MORETEXT_API_URL = "http://more.handlino.com/sentences.json"

    class << self
      def fetch_moretext(number, limit)
        number = "n=#{number}"
        limit  = parse(limit)
        condition = limit.nil? ? "?#{number}" : "?#{number}&#{limit}"
        return JSON(open("#{MORETEXT_API_URL}#{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.5 lib/chh_moretext.rb
chh_moretext-0.1.4 lib/chh_moretext.rb