Code Monkey home page Code Monkey logo

Comments (5)

geemus avatar geemus commented on August 15, 2024

Could you provide a short example script with some fake data of what the data looks like, what command (roughly) you'd like to run and what output you hope to see? I think that will just help clarify that we are on the same page before I dig too deep down a blind alley.

from formatador.

jacobbednarz avatar jacobbednarz commented on August 15, 2024

Sure!

Example response from the third party.

→ http https://api.example.com/ssh_users.json

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 112
Content-Type: application/json;charset=utf-8
Date: Mon, 06 Jan 2014 19:28:29 GMT
Server: nginx
Status: 200 OK
X-Content-Type-Options: nosniff
X-Rate-Limit-Limit: 360
X-Rate-Limit-Remaining: 359
X-Rate-Limit-Reset: 1389038400

[
    {
        "id": "11744", 
        "nickname": "[email protected]"
    }, 
    {
        "id": "23228", 
        "nickname": "[email protected]"
    }, 
    {
        "id": "23229", 
        "nickname": "[email protected]"
    }
]

In terms of the command, I am not 100% sure where it would best fit - maybe an extra hash of actual fields => rewritten output field? E.g. Formatador.display_table(table_data, [:id, :nickname => "username"]).

from formatador.

geemus avatar geemus commented on August 15, 2024

Hmm. Trying to think how to make this easier. Perhaps you can just do something like:

response = JSON.parse(Excon.get('https://api.example.com/ssh_users.json').body)
data = Hash.new do |hash, key|
  case key
  when 'username'
    hash['nickname']
  else
    nil
  end
end
data.merge!(response)
Formatador.display_table(data)

Just wanted to offer some kind of fix that involved less iterating for you, since I too am unsure where one might best fit in those extra fields.

from formatador.

jacobbednarz avatar jacobbednarz commented on August 15, 2024

The more I think about this, the more I am convinced that this requirement should be outside of the scope of Formatador as it isn't anything to do with the outputting of the table, it is altering the data that is returned which is the issue here.

If you don't have anything further to add I am happy to close this off and leave it as is.

Thanks for the replies though!

from formatador.

geemus avatar geemus commented on August 15, 2024

@jacobbednarz - alright. I certainly see how something like this could be helpful, but there are also points for keeping the table stuff simple. So, yeah, lets just leave it for now. Thanks for the feedback and discussion!

from formatador.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.