Class: Zoom

Inherits:
Object
  • Object
show all
Defined in:
lib/zoom.rb

Defined Under Namespace

Classes: Cache, Config, Editor, Error, Profile, ProfileManager, SecurityProfile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache = nil, rc = nil) ⇒ Zoom

Returns a new instance of Zoom.



88
89
90
91
92
# File 'lib/zoom.rb', line 88

def initialize(cache = nil, rc = nil)
    @config = Zoom::Config.new(rc)
    @cache = Zoom::Cache.new(@config, cache)
    @@hilight = @config.hilight?
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



5
6
7
# File 'lib/zoom.rb', line 5

def cache
  @cache
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/zoom.rb', line 6

def config
  @config
end

Class Method Details

.hilight(hilight = true) ⇒ Object



79
80
81
# File 'lib/zoom.rb', line 79

def self.hilight(hilight = true)
    @@hilight = hilight
end

.hilight?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/zoom.rb', line 83

def self.hilight?
    @@hilight ||= false
    return @@hilight
end

Instance Method Details

#open(results) ⇒ Object



94
95
96
97
# File 'lib/zoom.rb', line 94

def open(results)
    return if (results.nil? || results.empty?)
    Zoom::Editor.new(@config.get_editor).open(results)
end

#repeat(shortcut = true) ⇒ Object



99
100
101
102
# File 'lib/zoom.rb', line 99

def repeat(shortcut = true)
    return if (@cache.empty?)
    run(@cache.header, shortcut, true)
end

#run(h, shortcut = true, repeat = false) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/zoom.rb', line 104

def run(h, shortcut = true, repeat = false)
    # Don't change the header passed in
    header = h.clone

    # Ensure header is formatted properly and valid
    header = ensure_valid_header(header) if (!repeat)
    header["pwd"] = Dir.pwd if (repeat)

    profile_name = header["profile_name"]
    profile = @config.get_profile(profile_name)

    begin
        # Clear cache
        @cache.clear

        # Store needed details
        @cache.header(header)

        # Translate any needed flags
        header["translated"] = profile.translate(
            header["translate"]
        ).strip

        # This may append args such that the output will be
        # something Zoom can process
        header = profile.preprocess(header)

        # Execute profile
        @cache.write(profile.exe(header), header["regex"])

        # Display results from cache
        @cache.shortcut if (shortcut)
    rescue Interrupt
        # ^C
    end
end