slavkatag 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3a5f98d4134b90600977b86542ef4e9f53104b6
4
+ data.tar.gz: c1e2549178a971d170a279a790dc58f453400157
5
+ SHA512:
6
+ metadata.gz: 4f79fc9d750cc220a74f528f877baebb724e2e77b4afd139c2ca1723dbf8c7f0891bc9487ad368d94de27932a4c590f1996a30872455413513813a35701841b1
7
+ data.tar.gz: 0e1496fa171618f9201a4bb614d0e6050bb47c447d1681f636ff13314018dba01d9fad70b00c6e42342e138fe7b599a73fcf2fc5446bc836844511cc7fa6ac9b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in slavkatag.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # Slavkatag
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/slavkatag`. 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 'slavkatag'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install slavkatag
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]/slavkatag.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "slavkatag"
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
@@ -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
@@ -0,0 +1,136 @@
1
+ require "slavkatag/version"
2
+
3
+ module SRTParser
4
+ def SRTParser.parse_file path_to_file
5
+ file_path = path_to_file
6
+ final = Hash.new(0)
7
+ def self.number_of_lines file_path
8
+ file = File.open(file_path)
9
+ number_of_lines = 0
10
+ file.each_line do |line|
11
+ line = line.gsub /[-0-9:,>\n]/,''
12
+ if line != ""
13
+ number_of_lines += 1
14
+ end
15
+ end
16
+ return number_of_lines
17
+ end
18
+ def self.number_of_words file_path
19
+ file = File.open(file_path)
20
+ number_of_words = 0
21
+ file.each_line do |line|
22
+ words = line.split
23
+ words.each do |word|
24
+ word = word.gsub /[-0-9:,>]/,''
25
+ if word != ""
26
+ number_of_words += 1
27
+ end
28
+ end
29
+ end
30
+ return number_of_words
31
+ end
32
+ def self.number_of_symbols file_path
33
+ file = File.open(file_path)
34
+ number_of_symbols = 0
35
+ file.each_line do |line|
36
+ words = line.split
37
+ words.each do |word|
38
+ word = word.gsub /[-0-9:,>]/,''
39
+ if count = word.scan(/[\~\!\@\#\$\%\^\&\*\(\)\-\{\}\[\]\|\"\:\>\<\?\/]/).count
40
+ number_of_symbols += count
41
+ end
42
+ end
43
+ end
44
+ return number_of_symbols
45
+ end
46
+ def self.max_symbols_per_line file_path
47
+ max_symbols_per_line = 0
48
+ count = 0
49
+ file = File.open(file_path)
50
+ file.each_line do |line|
51
+ line = line.gsub(/[-0-9:,>]/,'')
52
+ if line != ''
53
+ count = line.scan(/[\~\!\@\#\$\%\^\&\*\(\)\-\{\}\[\]\|\"\:\>\<\?\/]/).count
54
+ if max_symbols_per_line < count
55
+ max_symbols_per_line = count
56
+ end
57
+ end
58
+ end
59
+ return max_symbols_per_line
60
+ end
61
+ def self.number_of_sentences file_path
62
+ number_of_sentences = 0
63
+ file = File.open(file_path)
64
+ file.each_line do |line|
65
+ line = line.gsub(/[-0-9:,>]/,'')
66
+ if line != ''
67
+ line = line.split
68
+ line.each do |word|
69
+ if word =~ /[^A-Z]*/
70
+ state = 1
71
+ end
72
+ if state == 1
73
+ if word =~ (/[. ? !]/)
74
+ state = 0
75
+ number_of_sentences += 1
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ return number_of_sentences
82
+ end
83
+ def self.duration file_path
84
+ duration = 0.0
85
+ first_line_state = 0
86
+ last_line = 0
87
+ first_line = 0
88
+ file = File.open(file_path)
89
+ file.each_line do |line|
90
+ if line =~ /[>]/ && first_line_state == 0
91
+ time = line.byteslice(0,12)
92
+ hours = time.byteslice(0,2).to_i
93
+ minutes = time.byteslice(3,2).to_i
94
+ seconds = time.byteslice(6,2).to_i
95
+ miliseconds = time.byteslice(9,3).to_i
96
+ first_line_state = 1
97
+ minutes += hours*60
98
+ seconds += minutes*60
99
+ first_line = seconds.to_f + (miliseconds.to_f/1000)
100
+ end
101
+ if line =~ /[>]/
102
+ time = line.byteslice(15,12)
103
+ hours = time.byteslice(0,2).to_i
104
+ minutes = time.byteslice(3,2).to_i
105
+ seconds = time.byteslice(6,2).to_i
106
+ miliseconds = time.byteslice(9,2).to_i
107
+ minutes += hours*60
108
+ seconds += minutes*60
109
+ last_line = seconds.to_f + (miliseconds.to_f/1000)
110
+ end
111
+ end
112
+ duration += last_line - first_line
113
+ return duration.round(2)
114
+ end
115
+ def self.number_of_subtitles file_path
116
+ number_of_subtitles = 0
117
+ file = File.open(file_path)
118
+ file.each_line do |line|
119
+ if line.scan(/[0-9]/).count > 17
120
+ number_of_subtitles += 1
121
+ end
122
+ end
123
+ return number_of_subtitles
124
+ end
125
+ final["number_of_words"] = number_of_words file_path
126
+ final["number_of_symbols"] = number_of_symbols file_path
127
+ final["number_of_lines"] = number_of_lines file_path
128
+ final["average_symbols_per_line"] = ((number_of_symbols file_path ).to_f/(number_of_lines file_path).to_f).round(2)
129
+ final["max_symbols_per_line"] = max_symbols_per_line file_path
130
+ final["number_of_sentences"] = number_of_sentences file_path
131
+ final["average_symbols_per_sentence"] = ((number_of_symbols file_path).to_f / (number_of_sentences file_path).to_f).round(2)
132
+ final["duration"] = (duration file_path).round()
133
+ final["average_duration"] = ((duration file_path).to_f / (number_of_subtitles file_path).to_f).round(2)
134
+ return final
135
+ end
136
+ end
@@ -0,0 +1,3 @@
1
+ module Slavkatag
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slavkatag/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slavkatag"
8
+ spec.version = Slavkatag::VERSION
9
+ spec.authors = ["Slav Kirilov"]
10
+ spec.email = ["slavkirilov00@gmail.com"]
11
+
12
+ spec.summary = %q{ Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{ Write a longer description or delete this line.}
14
+ spec.homepage =""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slavkatag
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Slav Kirilov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-29 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: " Write a longer description or delete this line."
42
+ email:
43
+ - slavkirilov00@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - lib/slavkatag.rb
55
+ - lib/slavkatag/version.rb
56
+ - slavkatag.gemspec
57
+ homepage: ''
58
+ licenses: []
59
+ metadata:
60
+ allowed_push_host: https://rubygems.org
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.7
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Write a short summary, because Rubygems requires one.
81
+ test_files: []