chh_moretext 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -47,6 +47,12 @@ ChhMoretext::Moretext.paragraphs(5)
47
47
  # 也可以指定要有幾個段落
48
48
  ```
49
49
 
50
+ ## Issues
51
+
52
+ 目前已知的問題……
53
+
54
+ * limit 如果設一個字,例如給出 /sentences.json?n=3&limit=1 這個 URL 請求,Moretext 伺服器就會死機好一陣子;
55
+
50
56
  ## TODO
51
57
 
52
58
  * 目前每呼叫一個方法就是一個 request,造成產生假文的速度非常緩慢,打算弄個「快取層」先把資料抓來,呼叫方法時從快取裡面去拿;
data/lib/chh_moretext.rb CHANGED
@@ -7,23 +7,20 @@ module ChhMoretext
7
7
  class << self
8
8
  def fetch_moretext(number, limit)
9
9
  number = "n=#{number}"
10
-
11
- if limit.is_a?(Range)
12
- limit = "limit=#{limit.min},#{limit.max}"
13
- elsif limit.is_a?(Integer)
14
- limit = "limit=#{limit}"
15
- else
16
- limit = nil
17
- end
18
-
19
- if limit.nil?
20
- condition = "?#{number}"
21
- else
22
- condition = "?#{number}&#{limit}"
23
- end
10
+ limit = parse(limit)
11
+ condition = limit.nil? ? "?#{number}" : "?#{number}&#{limit}"
24
12
  return JSON(open("http://more.handlino.com/sentences.json#{condition}").read)["sentences"]
25
13
  end
26
14
  end
15
+
16
+ private
17
+ def self.parse(type)
18
+ case type
19
+ when Range then "limit=#{type.min},#{type.max}"
20
+ when Integer then "limit=#{type}"
21
+ else nil
22
+ end
23
+ end
27
24
  end
28
25
  end
29
26
 
@@ -1,3 +1,3 @@
1
1
  module ChhMoretext
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chh_moretext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: