Skip to content

Instantly share code, notes, and snippets.

@lukesarnacki
Created June 4, 2012 07:41
Show Gist options
  • Select an option

  • Save lukesarnacki/2866996 to your computer and use it in GitHub Desktop.

Select an option

Save lukesarnacki/2866996 to your computer and use it in GitHub Desktop.
class YmlLength
attr_accessor :data, :result
def initialize(path)
self.data = YAML::load_file(Rails.root.join(path)).to_a.flatten.last
self.result = ""
get_value(data)
end
def get_value(d)
if d.is_a?(Hash)
d.each do |k, v|
get_value(v)
end
else
self.result << " " + d.to_s
end
end
end
@lukesarnacki
Copy link
Copy Markdown
Author

load 'yml_check.rb'
YmlLength.new(Rails.root.join('config/locales/pl.yml')).result.length #wszystkie znaki
YmlLength.new(Rails.root.join('config/locales/pl.yml')).result.gsub(' ', '').length #bez spacji
YmlLength.new(Rails.root.join('config/locales/pl.yml')).result.split(' ').length # wyrazy
YmlLength.new(Rails.root.join('config/locales/pl.yml')).result.split(' ').delete_if {|w| w.length < 2 }.length # wyrazy co najmniej 2 literowe

Łączna liczba znaków:
Liczba znaków, bez spacji:
Liczba wyrazów:
Liczba wyrazów co najmniej 2 literowych:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment