### Home Classes Methods

### In Files

- lib/stella/core_ext.rb

### Parent

Object

### Methods

- #encode_fix
- #in_seconds
- #linkify
- #linkify!
- #plural
- #shorten
- #to_file

### Files

- LICENSE.txt
- TODO

### Class/Module Index

Quicksearch

- Stella
- Stella::API
- Stella::API::Unauthorized
- Stella::Asserts
- Stella::CLI
- Stella::Client
- Stella::Common
- Stella::Common::PrivacyMethods
- Stella::ET
- Stella::Engine
- Stella::Engine::Base
- Stella::Engine::Base::ClassMethods
- Stella::Engine::Checkup
- Stella::EventTemplate
- Stella::ForcedRedirect
- Stella::HTTPError
- Stella::Log
- Stella::Log::HTTP
- Stella::PageError
- Stella::RT
- Stella::RepeatRequest
- Stella::Report
- Stella::Report::Content
- Stella::Report::Content::ReportMethods
- Stella::Report::Errors
- Stella::Report::Errors::ReportMethods
- Stella::Report::Headers
- Stella::Report::Metrics
- Stella::Report::Metrics::ReportMethods
- Stella::Report::Plugin
- Stella::Report::Plugin::ClassMethods
- Stella::Report::Statuses
- Stella::Report::Statuses::ReportMethods
- Stella::RequestError
- Stella::RequestTemplate
- Stella::Session
- Stella::StringTemplate
- Stella::TP
- Stella::Testplan
- Stella::Testplan::ClassMethods
- Stella::TestplanQuit
- Stella::Testrun
- Stella::TimeoutError
- Stella::UC
- Stella::Usecase
- Stella::Usecase::ClassMethods
- Stella::UsecaseError
- Stella::UsecaseFail
- Stella::Utils
- Stella::VERSION
- Addressable
- Addressable::URI
- Time
- Time::Units
- Array
- DefaultTestplan
- Float
- Hash
- MatchData
- MetricsPack
- Numeric
- Object
- OpenStruct
- StellaBehavior
- StellaError
- String
- Symbol
- Thread

No matching classes.

# String

Assumes Time::Units and Numeric mixins are available.

### Public Instance Methods

encode_fix(enc="UTF-8") click to toggle source

    # File lib/stella/core_ext.rb, line 124
    def encode_fix(enc="UTF-8")
      if RUBY_VERSION >= "1.9"
        begin
          encode!(enc, :undef => :replace, :invalid => :replace, :replace => '?')
        rescue Encoding::CompatibilityError
          BS.info "String#encode_fix: resorting to US-ASCII"
          encode!("US-ASCII", :undef => :replace, :invalid => :replace, :replace => '?')
        end
      end
      self
    end

in_seconds() click to toggle source

    # File lib/stella/core_ext.rb, line 114
    def in_seconds
      # "60m" => ["60", "m"]
      q,u = self.scan(/([\d\.]+)([s,m,h])?/).flatten
      q &&= q.to_f and u ||= 's'
      q &&= q.in_seconds(u)
    end

linkify() click to toggle source

    # File lib/stella/core_ext.rb, line 165
    def linkify
       self.dup.linkify!
    end

linkify!() click to toggle source

via: www.est1985.nl/design/2-design/96-linkify-urls-in-ruby-on-rails

    # File lib/stella/core_ext.rb, line 152
    def linkify!
      self.gsub!(/\b((https?:\/\/|ftps?:\/\/|mailto:|www\.|status\.)([A-Za-z0-9\-_=%&amp;@\?\.\/]+(\/\s)?))\b/) {
        match = $1
        tail  = $3
        case match
        when /^(www|status)/     then  "<a href=\"http://#{match.strip}\">#{match}</a>"
        when /^mailto/  then  "<a href=\"#{match.strip}\">#{tail}</a>"
        else                  "<a href=\"#{match.strip}\">#{match}</a>"
        end
      }
      self
    end

plural(int=1) click to toggle source

    # File lib/stella/core_ext.rb, line 135
    def plural(int=1)
      int > 1 || int.zero? ? "#{self}s" : self
    end

shorten(len=50) click to toggle source

    # File lib/stella/core_ext.rb, line 138
    def shorten(len=50)
      return self if size <= len
      self[0..len] + "..."
    end

to_file(filename, mode, chmod=0744) click to toggle source

    # File lib/stella/core_ext.rb, line 142
    def to_file(filename, mode, chmod=0744)
      mode = (mode == :append) ? 'a' : 'w'
      f = File.open(filename,mode)
      f.puts self
      f.close
      raise "Provided chmod is not a Fixnum (#{chmod})" unless chmod.is_a?(Fixnum)
      File.chmod(chmod, filename)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.