yawc 0.1.0
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/lib/yawc.rb +41 -0
- metadata +68 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d20985fb62b69440f25801ad9cf77bb3962fa2c
|
4
|
+
data.tar.gz: 32b4324643dbb06fc04249f4b50e165956c818c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f673cc07ef2e057f0a6a66501b4b576795a20395b27ae72e2609f8e53bff3b5f7db0a11f969d49c8379bd81db1910a9fd628c193924573c3dfc0a938938d58fb
|
7
|
+
data.tar.gz: 5b5a37348f02764cc8e64050dde1f4afbb6086136f31de21a35a7037f945994ff680ee6559290cde863896e1f51a3eb2b740f3d03384f61b709fcf31b5b95a9f
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
K�zrh�!Α�������b���=g�t��(������v��%�BT65��D�AI�#�$3挬�{��%���V�����63U��b��g*y������(i`�_�`�юI���AY�����d���l���n����NU\�u�ޓ��^�����G�Ak;��r��U��;�f�K��+�����v,¯��H3��V�8��S��"u�|P�,>�@F�+_�"��S���
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/yawc.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: yawc.rb
|
4
|
+
|
5
|
+
# description: Yet Another Word Counter (YAWC) makes it convenient to
|
6
|
+
# count the number of words in a string and return the
|
7
|
+
# result as a hash object.
|
8
|
+
|
9
|
+
# note: A hashtag is identified as a word e.g. #liveblog
|
10
|
+
|
11
|
+
class Yawc
|
12
|
+
|
13
|
+
attr_reader :to_h
|
14
|
+
|
15
|
+
def initialize(s)
|
16
|
+
|
17
|
+
h = words(s).split.group_by(&:to_s).\
|
18
|
+
inject({}){|r, x| r.merge(String.new(x[0]).\
|
19
|
+
force_encoding("utf-8") => x[-1].length)}
|
20
|
+
@to_h = h.sort_by(&:last).reverse.to_h
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def words(s)
|
25
|
+
|
26
|
+
ignorewords = ['or', 'the', 'of', 'a', 'if', 'to', 'and',
|
27
|
+
'in', 'is', 'are', 'as', 'it', 'at']
|
28
|
+
|
29
|
+
s.downcase.
|
30
|
+
gsub(/\w+'\w+/,''). # remove words containing an apostrophe
|
31
|
+
gsub(/["']/,''). # remove quotation marks
|
32
|
+
gsub(/\W[^a-z|#]+(\w+)/,' \1 '). # remove
|
33
|
+
# non-alpabetical characters from start or beginning of words
|
34
|
+
gsub(/\s.\s/,' '). # remove single digits
|
35
|
+
gsub(/\b(?:#{ignorewords.join('|')})\b/,''). # ignore common words
|
36
|
+
gsub(/\B[^\w#]\B+/,'') # remove any other items which are
|
37
|
+
# not words or hashtags
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yawc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE2MDUwNDE4MDQ1MVoXDTE3MDUwNDE4MDQ1MVowSDESMBAG
|
16
|
+
A1UE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MpadRAi8c8u7wGKi5MwsvHjL
|
31
|
+
OlLHmevAiPqMymXu8xRan6xS9e+dvZ+AILldPh7L4F/kSGbrw8vknyGCQWmx+ObA
|
32
|
+
zkV6CoocsL1OSQ==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
35
|
+
dependencies: []
|
36
|
+
description:
|
37
|
+
email: james@r0bertson.co.uk
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/yawc.rb
|
43
|
+
homepage: https://github.com/jrobertson/yawc
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.8
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Yet Another Word Counter (YAWC) makes it convenient to count the number
|
67
|
+
of words in a string and return the result as a hash object.
|
68
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|