Slavkata 1.0.1

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
+ SHA1:
3
+ metadata.gz: f18f83ffb18c9f6a106ba46bc8d2ac92580fdaa7
4
+ data.tar.gz: 284ecb66c8e45035b14552b09ae56f17d06f11ec
5
+ SHA512:
6
+ metadata.gz: 89590bf7709e563fa13c24a1aa4c6af9b0c05988be279d50708f2784bc0030e80316fa1a246b67ea7d0902f1fa3e43085d5db5f9da181b26ae81565d50bce504
7
+ data.tar.gz: 8b9272a849abee4a474ff0ae0097026cb4dacfc4b125f69ff64f5051f0536416d109703899aaf276b68b932bf7654ba2730ca747e268ae53f3e75272b4bc8591
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in Slavkata.gemspec
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Slavkata (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.5.0)
12
+ rspec-core (~> 3.5.0)
13
+ rspec-expectations (~> 3.5.0)
14
+ rspec-mocks (~> 3.5.0)
15
+ rspec-core (3.5.4)
16
+ rspec-support (~> 3.5.0)
17
+ rspec-expectations (3.5.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.5.0)
20
+ rspec-mocks (3.5.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-support (3.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ Slavkata!
30
+ bundler (~> 1.3)
31
+ rake
32
+ rspec
33
+
34
+ BUNDLED WITH
35
+ 1.13.6
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Slavkata
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Slavkata`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'Slavkata'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install Slavkata
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Slavkata.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/Slavkata.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Slavkata/version.rb'
5
+ require 'rake'
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Slavkata"
8
+ spec.version = "1.0.1"
9
+ spec.authors = ["Slav Kirilov"]
10
+ spec.email = ["slavkirilov00@gmail.com"]
11
+ spec.description = %q{Parse .srt files}
12
+ spec.summary = %q{Counting specific parts in the file}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = FileList['lib/Slavkata.rb',
17
+ 'bin/*',
18
+ '[A-Z]*',
19
+ 'test/ *'].to_a
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Slavkata"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/Slavkata.rb ADDED
@@ -0,0 +1,135 @@
1
+ require "Slavkata/version"
2
+ module SRTParser
3
+ def parse_file path_to_file
4
+ file_path = path_to_file
5
+ final = Hash.new(0)
6
+ def number_of_lines file_path
7
+ file = File.open(file_path)
8
+ number_of_lines = 0
9
+ file.each_line do |line|
10
+ line = line.gsub /[-0-9:,>\n]/,''
11
+ if line != ""
12
+ number_of_lines += 1
13
+ end
14
+ end
15
+ return number_of_lines
16
+ end
17
+ def number_of_words file_path
18
+ file = File.open(file_path)
19
+ number_of_words = 0
20
+ file.each_line do |line|
21
+ words = line.split
22
+ words.each do |word|
23
+ word = word.gsub /[-0-9:,>]/,''
24
+ if word != ""
25
+ number_of_words += 1
26
+ end
27
+ end
28
+ end
29
+ return number_of_words
30
+ end
31
+ def number_of_symbols file_path
32
+ file = File.open(file_path)
33
+ number_of_symbols = 0
34
+ file.each_line do |line|
35
+ words = line.split
36
+ words.each do |word|
37
+ word = word.gsub /[-0-9:,>]/,''
38
+ if count = word.scan(/[\~\!\@\#\$\%\^\&\*\(\)\-\{\}\[\]\|\"\:\>\<\?\/]/).count
39
+ number_of_symbols += count
40
+ end
41
+ end
42
+ end
43
+ return number_of_symbols
44
+ end
45
+ def max_symbols_per_line file_path
46
+ max_symbols_per_line = 0
47
+ count = 0
48
+ file = File.open(file_path)
49
+ file.each_line do |line|
50
+ line = line.gsub(/[-0-9:,>]/,'')
51
+ if line != ''
52
+ count = line.scan(/[\~\!\@\#\$\%\^\&\*\(\)\-\{\}\[\]\|\"\:\>\<\?\/]/).count
53
+ if max_symbols_per_line < count
54
+ max_symbols_per_line = count
55
+ end
56
+ end
57
+ end
58
+ return max_symbols_per_line
59
+ end
60
+ def number_of_sentences file_path
61
+ number_of_sentences = 0
62
+ file = File.open(file_path)
63
+ file.each_line do |line|
64
+ line = line.gsub(/[-0-9:,>]/,'')
65
+ if line != ''
66
+ line = line.split
67
+ line.each do |word|
68
+ if word =~ /[^A-Z]*/
69
+ state = 1
70
+ end
71
+ if state == 1
72
+ if word =~ (/[. ? !]/)
73
+ state = 0
74
+ number_of_sentences += 1
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ return number_of_sentences
81
+ end
82
+ def duration file_path
83
+ duration = 0.0
84
+ first_line_state = 0
85
+ last_line = 0
86
+ first_line = 0
87
+ file = File.open(file_path)
88
+ file.each_line do |line|
89
+ if line =~ /[>]/ && first_line_state == 0
90
+ time = line.byteslice(0,12)
91
+ hours = time.byteslice(0,2).to_i
92
+ minutes = time.byteslice(3,2).to_i
93
+ seconds = time.byteslice(6,2).to_i
94
+ miliseconds = time.byteslice(9,3).to_i
95
+ first_line_state = 1
96
+ minutes += hours*60
97
+ seconds += minutes*60
98
+ first_line = seconds.to_f + (miliseconds.to_f/1000)
99
+ end
100
+ if line =~ /[>]/
101
+ time = line.byteslice(15,12)
102
+ hours = time.byteslice(0,2).to_i
103
+ minutes = time.byteslice(3,2).to_i
104
+ seconds = time.byteslice(6,2).to_i
105
+ miliseconds = time.byteslice(9,2).to_i
106
+ minutes += hours*60
107
+ seconds += minutes*60
108
+ last_line = seconds.to_f + (miliseconds.to_f/1000)
109
+ end
110
+ end
111
+ duration += last_line - first_line
112
+ return duration.round(2)
113
+ end
114
+ def number_of_subtitles file_path
115
+ number_of_subtitles = 0
116
+ file = File.open(file_path)
117
+ file.each_line do |line|
118
+ if line.scan(/[0-9]/).count > 17
119
+ number_of_subtitles += 1
120
+ end
121
+ end
122
+ return number_of_subtitles
123
+ end
124
+ final["number_of_words"] = number_of_words file_path
125
+ final["number_of_symbols"] = number_of_symbols file_path
126
+ final["number_of_lines"] = number_of_lines file_path
127
+ final["average_symbols_per_line"] = ((number_of_symbols file_path ).to_f/(number_of_lines file_path).to_f).round(2)
128
+ final["max_symbols_per_line"] = max_symbols_per_line file_path
129
+ final["number_of_sentences"] = number_of_sentences file_path
130
+ final["average_symbols_per_sentence"] = ((number_of_symbols file_path).to_f / (number_of_sentences file_path).to_f).round(2)
131
+ final["duration"] = duration file_path.round
132
+ final["average_duration"] = ((duration file_path).to_f / (number_of_subtitles file_path).to_f).round(2)
133
+ return final
134
+ end
135
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Slavkata
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Slav Kirilov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Parse .srt files
56
+ email:
57
+ - slavkirilov00@gmail.com
58
+ executables:
59
+ - console
60
+ - setup
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - README.md
67
+ - Rakefile
68
+ - Slavkata.gemspec
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/Slavkata.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.6.7
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Counting specific parts in the file
96
+ test_files: []