lara-text_utils 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07cfeb0fc430200123dc070db08f08e9e37977ee296faf65d95813dcd3a0bd25
4
+ data.tar.gz: '09e730885f4409f96d475b2a8021212dd43ebf79330ec2b3a7ddc0e476e185db'
5
+ SHA512:
6
+ metadata.gz: 3dd4014ea5bc8dc77544db71ef7d53fae5ac06c7140d50bacb7453863762f30bf1b919e9f243f05c0b8c8742234be9e9dbad27e6762cf87328ff86cb1c6f4b92
7
+ data.tar.gz: 521e2d7e8bf9c45a07c0204c238c4e51354f06a18a6a6c9d664e6d32a544ff44b3bd0a5927f79a9b27a354f2910749bbb5eb24f8796390d475126974ef7a875d
@@ -0,0 +1,68 @@
1
+ module Lara
2
+ module TextUtils
3
+ class Analyzer
4
+ def initialize(text)
5
+ @text = text.to_s
6
+ end
7
+
8
+ def word_count
9
+ @text.scan(/[[:alpha:]]+/).size
10
+ end
11
+
12
+ def sentence_count
13
+ @text.scan(/[.!?]+/).size
14
+ end
15
+
16
+ def char_count
17
+ @text.size
18
+ end
19
+
20
+ def char_count_no_spaces
21
+ @text.gsub(/\s+/, "").size
22
+ end
23
+
24
+ def average_word_length
25
+ words = @text.scan(/[[:alpha:]]+/)
26
+ return 0.0 if words.empty?
27
+ words.sum(&:length).to_f / words.size
28
+ end
29
+
30
+ def lexical_density
31
+ words = @text.scan(/[[:alpha:]]+/).map(&:downcase)
32
+ return 0.0 if words.empty?
33
+ (words.uniq.size.to_f / words.size * 100).round(1)
34
+ end
35
+
36
+ def reading_time(wpm: 200)
37
+ minutes = word_count.to_f / wpm
38
+ if minutes < 1
39
+ "#{(minutes * 60).round} seconds"
40
+ elsif minutes < 60
41
+ "#{minutes.round} min"
42
+ else
43
+ "#{(minutes / 60).round}h #{(minutes % 60).round}m"
44
+ end
45
+ end
46
+
47
+ def summary(max_length: 100)
48
+ clean = @text.gsub(/\s+/, " ").strip
49
+ return clean if clean.length <= max_length
50
+ cut = clean[0...max_length]
51
+ cut = cut[0...cut.rindex(/\s/)] || cut
52
+ cut + "..."
53
+ end
54
+
55
+ def stats
56
+ {
57
+ word_count: word_count,
58
+ sentence_count: sentence_count,
59
+ char_count: char_count,
60
+ char_count_no_spaces: char_count_no_spaces,
61
+ average_word_length: average_word_length.round(2),
62
+ lexical_density: lexical_density,
63
+ reading_time: reading_time
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Lara
2
+ module TextUtils
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "text_utils/version"
2
+ require_relative "text_utils/analyzer"
3
+
4
+ module Lara
5
+ module TextUtils
6
+ class Error < StandardError; end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lara-text_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lara AI
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: 'A simple Ruby gem for analyzing text: word count, sentence count, lexical
13
+ density, reading time, and more. Created with honesty.'
14
+ email: jarod79tm@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/lara/text_utils.rb
20
+ - lib/lara/text_utils/analyzer.rb
21
+ - lib/lara/text_utils/version.rb
22
+ homepage: https://rubygems.org/profiles/lara-entity-ai
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ source_code_uri: https://rubygems.org/profiles/lara-entity-ai
27
+ rubygems_mfa_required: 'false'
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '2.7'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.6.7
43
+ specification_version: 4
44
+ summary: Text analysis utilities — word count, readability, stats
45
+ test_files: []