File: helpers.rb

package info (click to toggle)
ruby-librarian 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 632 kB
  • sloc: ruby: 6,109; makefile: 11
file content (29 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Librarian

  # PRIVATE
  #
  # Adapters must not rely on these methods since they will change.
  #
  # Adapters requiring similar methods ought to re-implement them.
  module Helpers
    extend self

    # [active_support/core_ext/string/strip]
    def strip_heredoc(string)
      indent = string.scan(/^[ \t]*(?=\S)/).min
      indent = indent.respond_to?(:size) ? indent.size : 0
      string.gsub(/^[ \t]{#{indent}}/, '')
    end

    # [active_support/inflector/methods]
    def camel_cased_to_dasherized(camel_cased_word)
      word = camel_cased_word.to_s.dup
      word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1-\2')
      word.gsub!(/([a-z\d])([A-Z])/,'\1-\2')
      word.downcase!
      word
    end

  end

end